blob: 31ebfd44708b5060858bb0be2a3de008f9926815 [file]
// 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"],
default_team: "trendy_team_system_performance",
}
android_test {
name: "AppMemoryTestCases",
team: "trendy_team_system_performance",
srcs: ["src/**/*.java"],
exclude_srcs: ["src/**/host/*.java"],
static_libs: [
"androidx.test.rules",
"androidx.test.core",
"platform-test-annotations",
"flag-junit",
"androidx.test.uiautomator_uiautomator",
"collector-device-lib",
],
device_common_data: [
":AppMemoryTest_Helper",
],
data: [
"perfetto.textproto",
],
platform_apis: true,
test_suites: [
"device-tests",
"performance-tests",
],
test_config: "AppMemoryTest.xml",
certificate: "platform",
}
// Generate code to artificially bloat the test helper app.
// This is to add enough code to the app so that its size is representative of
// a real large app.
genrule {
name: "AppMemoryTest_Helper_gen_sources",
tools: ["soong_zip"],
tool_files: ["generate_java_sources.sh"],
cmd: "bash $(location generate_java_sources.sh) 5000 100 $(genDir)/src $(out) $(location soong_zip)",
out: ["generated_sources.srcjar"],
}
// Generate resources to artificially bloat the test helper app.
genrule {
name: "AppMemoryTest_Helper_gen_resources",
tools: ["soong_zip"],
tool_files: ["generate_resources.sh"],
cmd: "bash $(location generate_resources.sh) 100 1000 $(genDir)/res $(out) $(location soong_zip)",
out: ["generated_resources.zip"],
}
android_test_helper_app {
name: "AppMemoryTest_Helper",
manifest: "app/AndroidManifest.xml",
srcs: [
"app/src/**/*.java",
":AppMemoryTest_Helper_gen_sources",
],
resource_dirs: ["app/res"],
resource_zips: [":AppMemoryTest_Helper_gen_resources"],
test_suites: ["general-tests"],
certificate: "platform",
dex_preopt: {
enabled: false,
},
// Intentionally disable optimizations.
// Otherwise the generated bloat will be stripped.
optimize: {
enabled: false,
},
static_libs: [
"androidx.appcompat_appcompat",
],
// This prevents the use of dex version 041, which was introduced in API 35.
// Until dex version 041, large programs would span multiple physical dex
// files. This increased their static load in memory, for instance by
// requiring the runtime to have multiple PathClassLoader instances and
// multiple runtime dex caches.
// This is the common behavior in apps in the market today, so we would like
// to simulate it in our test load.
min_sdk_version: "34",
}
filegroup {
name: "appmemorytest_perfetto_config",
srcs: ["perfetto.textproto"],
}
filegroup {
name: "appmemorytest_metrics_artifacts",
srcs: [
"metrics/appmemorytest_binder_transactions.textproto",
"metrics/appmemorytest_native_allocations.textproto",
],
}
prebuilt_etc {
name: "appmemorytest_binder_transactions.textproto",
src: "metrics/appmemorytest_binder_transactions.textproto",
}
prebuilt_etc {
name: "appmemorytest_native_allocations.textproto",
src: "metrics/appmemorytest_native_allocations.textproto",
}
// A helper device binary used to calculate CoW memory redundancy during the test.
// We compile this as a separate cc_binary (rather than running logic on the host or inside the test app) because:
// 1. It needs to read `/proc/<pid>/pagemap` and `/proc/<pid>/maps` of the target app, which requires
// root permissions on the device to access pagemap entries.
// 2. It compares the raw physical memory contents of the target app's pages with the zygote's pages.
// Doing this memory comparison directly on the device is substantially faster and avoids pulling
// gigabytes of raw memory dumps to the host.
// 3. We static-link it (`static_executable: true` and `stl: "c++_static"`) to ensure it runs
// hermetically on any Android device variant without dynamic linker or shared library issues.
rust_binary {
name: "cow_estimator_helper",
crate_name: "cow_estimator_helper",
srcs: ["tools/cow_estimator.rs"],
host_supported: false,
static_executable: true,
rustlibs: [
"libclap",
"libitertools",
"liblibc",
"libregex",
],
}
// A hermetic host tool used by AppMemoryCoWHostTest to generate CoW-redundant pprof profiles.
// We package this as a python_binary_host because:
// 1. It requires simpleperf's pprof_proto_generator logic to read perf.data and output pprof files,
// which is written in Python and uses a native parser (libsimpleperf_report.so).
// 2. Packaging it hermetically with its libraries (like simpleperf_pprof_proto_generator_lib and protobuf)
// allows the host Java test to execute it reliably in the Tradefed sandbox without needing to
// install python packages or rely on host environment state.
python_binary_host {
name: "generate_cow_profiles",
srcs: [
"tools/generate_cow_profiles.py",
],
main: "tools/generate_cow_profiles.py",
libs: [
"simpleperf_pprof_proto_generator_lib",
],
}
rust_test_host {
name: "cow_estimator_test",
crate_name: "cow_estimator_test",
srcs: ["tools/cow_estimator.rs"],
rustlibs: [
"libclap",
"libitertools",
"liblibc",
"libregex",
],
test_suites: ["general-tests"],
}
python_test_host {
name: "generate_cow_profiles_test",
main: "tools/generate_cow_profiles_test.py",
srcs: [
"tools/generate_cow_profiles_test.py",
"tools/generate_cow_profiles.py",
],
libs: [
"simpleperf_pprof_proto_generator_lib",
],
test_suites: ["general-tests"],
}
java_test_host {
name: "AppMemoryHostTestCases",
team: "trendy_team_system_performance",
srcs: ["src/**/host/*.java"],
libs: [
"tradefed",
"compatibility-tradefed",
"compatibility-host-util",
],
static_libs: [
"frameworks-base-hostutils",
],
test_suites: [
"device-tests",
"performance-tests",
],
data_device_bins_first: [
"cow_estimator_helper",
],
device_common_data: [
":AppMemoryTest_Helper",
],
data_native_bins: [
"generate_cow_profiles",
],
test_config: "AppMemoryHostTest.xml",
}