Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perf tests: move setup android step from devops #26221

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion tools/perf/components/android_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,42 @@
import os
import re
import logging
import time

from typing import Optional
from typing import List, Optional

from components.perf_test_utils import GetProcessOutput
import components.path_util as path_util


def RunAsRoot(cmd: str) -> bool:
result, _ = GetProcessOutput(
[path_util.GetAdbPath(), 'shell', 'su', '-c', '\'' + cmd + '\''])
return result


def SetupAndroidDevice() -> None:
'''Pushes and run setup_android_device.sh script on the device.'''
tmp_file = '/data/local/tmp/setup_android_device.sh'
GetProcessOutput([
path_util.GetAdbPath(),
'push',
os.path.join(path_util.GetBravePerfDir(), 'setup_android_device.sh'),
tmp_file,
],
check=True)
if not RunAsRoot(f'sh {tmp_file}'):
raise RuntimeError('Failed to setup the device: setup_android_device.sh')
RunAsRoot('killall adbd') # Restart adbd on the device to apply the changes
time.sleep(2)


def RebootAndroid() -> None:
logging.debug('Rebooting Android device')
RunAsRoot('reboot')
time.sleep(30)


def GetPackageVersion(package: str) -> str:
_, dump_info = GetProcessOutput(
[path_util.GetAdbPath(), 'shell', 'dumpsys', 'package', package],
Expand Down
7 changes: 7 additions & 0 deletions tools/perf/components/common_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class CommonOptions:
working_directory: str = ''
target_os: str = PerfBenchmark.FixupTargetOS(sys.platform)
target_arch: str = ''
reboot_android: bool = False

do_report: bool = False
upload: bool = True
Expand Down Expand Up @@ -94,6 +95,10 @@ def add_parser_args(cls, parser: argparse.ArgumentParser) -> None:
type=str,
choices=['windows', 'mac', 'linux', 'android'])
parser.add_argument('--target-arch', type=str, choices=['x64', 'arm64'])
parser.add_argument(
'--reboot-android',
action='store_true',
help='Reboot the Android device before running the tests')
parser.add_argument(
'--local-run',
action='store_true',
Expand Down Expand Up @@ -176,6 +181,8 @@ def from_args(cls, args) -> 'CommonOptions':
else:
options.target_arch = 'x64'

options.reboot_android = args.reboot_android or args.ci_mode

options.report_on_failure = args.report_on_failure
if args.targets is not None:
options.targets = args.targets.split(',')
Expand Down
6 changes: 6 additions & 0 deletions tools/perf/run_perftests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import os
import tempfile

import components.android_tools as android_tools
import components.perf_config as perf_config
import components.perf_test_runner as perf_test_runner
import components.perf_test_utils as perf_test_utils
Expand Down Expand Up @@ -127,6 +128,11 @@ def main():
json_config = load_config(args.config, options)
config = perf_config.PerfConfig(json_config)

if options.is_android:
if options.reboot_android:
android_tools.RebootAndroid()
android_tools.SetupAndroidDevice()

if options.mode == PerfMode.RUN:
if len(config.runners) != 1:
raise RuntimeError('Only one configuration should be specified.')
Expand Down
17 changes: 17 additions & 0 deletions tools/perf/setup_android_device.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh
# Copyright (c) 2024 The Brave Authors. All rights reserved.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at https://mozilla.org/MPL/2.0/.

# The script is used to setup the android device:
# 1. Disable SELinux
# 2. Enable adb root (adbd must be restarted after)
# 3. Unlock the device screen

setenforce 0 && \
resetprop ro.debuggable 1 && \
magiskpolicy --live "allow adbd adbd process setcurrent" && \
magiskpolicy --live "allow adbd su process dyntransition" && \
magiskpolicy --live "permissive { su }" && \
input keyevent 82
Loading