Skip to content

Update hardcoded xHarness version and adb call flow #4635

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

Merged
merged 13 commits into from
Jan 14, 2025
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
9 changes: 4 additions & 5 deletions eng/performance/maui_scenarios_android.proj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

<PropertyGroup>
<IncludeXHarnessCli>true</IncludeXHarnessCli>
<MicrosoftDotNetXHarnessCLIVersion>1.0.0-prerelease.21566.2</MicrosoftDotNetXHarnessCLIVersion>
<XharnessPath>%HELIX_CORRELATION_PAYLOAD%\microsoft.dotnet.xharness.cli\$(MicrosoftDotNetXHarnessCLIVersion)\tools\net6.0\any\Microsoft.DotNet.XHarness.CLI.dll</XharnessPath>
<MicrosoftDotNetXHarnessCLIVersion>10.0.0-prerelease.24524.9</MicrosoftDotNetXHarnessCLIVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down Expand Up @@ -68,15 +67,15 @@
<Command>$(Python) test.py sod --scenario-name &quot;%(Identity)&quot; $(ScenarioArgs)</Command>
</HelixWorkItem>
<HelixWorkItem Include="@(MAUIAndroidScenario -> 'Device Startup - %(Identity)')">
<PreCommands>echo on; set XHARNESSPATH=$(XharnessPath); xcopy %HELIX_CORRELATION_PAYLOAD%\$(PreparePayloadOutDirectoryName)\%(HelixWorkItem.ScenarioDirectoryName) %HELIX_WORKITEM_ROOT%\pub\ /E /I /Y</PreCommands>
<PreCommands>echo on; xcopy %HELIX_CORRELATION_PAYLOAD%\$(PreparePayloadOutDirectoryName)\%(HelixWorkItem.ScenarioDirectoryName) %HELIX_WORKITEM_ROOT%\pub\ /E /I /Y</PreCommands>
<Command>$(Python) test.py devicestartup --device-type android --package-path pub\%(HelixWorkItem.ApkName).apk --package-name %(HelixWorkItem.PackageName) --scenario-name &quot;%(Identity)&quot; %(HelixWorkItem.StartupAdditionalArguments) $(ScenarioArgs)</Command>
</HelixWorkItem>
<HelixWorkItem Include="@(MAUIAndroidScenario -> 'Device Startup - %(Identity) NoAnimation')">
<PreCommands>echo on; set XHARNESSPATH=$(XharnessPath); xcopy %HELIX_CORRELATION_PAYLOAD%\$(PreparePayloadOutDirectoryName)\%(HelixWorkItem.ScenarioDirectoryName) %HELIX_WORKITEM_ROOT%\pub\ /E /I /Y</PreCommands>
<PreCommands>echo on; xcopy %HELIX_CORRELATION_PAYLOAD%\$(PreparePayloadOutDirectoryName)\%(HelixWorkItem.ScenarioDirectoryName) %HELIX_WORKITEM_ROOT%\pub\ /E /I /Y</PreCommands>
<Command>$(Python) test.py devicestartup --device-type android --package-path pub\%(HelixWorkItem.ApkName).apk --package-name %(HelixWorkItem.PackageName) --scenario-name &quot;%(Identity)&quot; --disable-animations %(HelixWorkItem.StartupAdditionalArguments) $(ScenarioArgs)</Command>
</HelixWorkItem>
<HelixWorkItem Include="@(MAUIAndroidScenario -> 'Memory Consumption - %(Identity)')" Condition="!$(HelixTargetQueue.ToLowerInvariant().Contains('galaxy'))">
<PreCommands>echo on; set XHARNESSPATH=$(XharnessPath); xcopy %HELIX_CORRELATION_PAYLOAD%\$(PreparePayloadOutDirectoryName)\%(HelixWorkItem.ScenarioDirectoryName) %HELIX_WORKITEM_ROOT%\pub\ /E /I /Y</PreCommands>
<PreCommands>echo on; xcopy %HELIX_CORRELATION_PAYLOAD%\$(PreparePayloadOutDirectoryName)\%(HelixWorkItem.ScenarioDirectoryName) %HELIX_WORKITEM_ROOT%\pub\ /E /I /Y</PreCommands>
<Command>$(Python) test.py devicememoryconsumption --device-type android --package-path pub\%(HelixWorkItem.ApkName).apk --package-name %(HelixWorkItem.PackageName) --scenario-name &quot;%(Identity)&quot; --runtime 30 --test-iteration 2 $(ScenarioArgs)</Command>
</HelixWorkItem>
</ItemGroup>
Expand Down
5 changes: 2 additions & 3 deletions scripts/performance/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
from stat import S_IWRITE
from subprocess import CalledProcessError
from subprocess import list2cmdline
from subprocess import PIPE, DEVNULL
from subprocess import PIPE, STDOUT, DEVNULL
from subprocess import Popen
from subprocess import STDOUT
from io import StringIO
from platform import machine

Expand Down Expand Up @@ -279,7 +278,7 @@ def __runinternal(self, working_directory: Optional[str] = None) -> Tuple[int, s

if '-AzureFeed' in self.cmdline or '-FeedCredential' in self.cmdline:
quoted_cmdline = "<dotnet-install command contains secrets, skipping log>"

getLogger().info(quoted_cmdline)

with Popen(
Expand Down
26 changes: 12 additions & 14 deletions src/scenarios/bdnandroid/pre.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from zipfile import ZipFile
from shutil import copyfile
from shared.const import PUBDIR
from shared.util import xharnesscommand
from shared.util import xharness_adb

from performance.common import RunCommand
from performance.logger import setup_loggers, getLogger
Expand Down Expand Up @@ -49,26 +49,24 @@
copyfile(apkname, os.path.join(PUBDIR, apkname))

if args.restart_device:
cmdline = xharnesscommand() + ['android', 'state', '--adb']
adb = RunCommand(cmdline, verbose=True)
adb.run()

# Do not remove, XHarness install seems to fail without an adb command called before the xharness command
getLogger().info("Preparing ADB")
adbpath = adb.stdout.strip()
# Try calling xharness with stdout=None and stderr=None to hopefully bypass the hang
getLogger().info("Clearing xharness stdout and stderr to avoid hang")
cmdline = xharness_adb() + [
'shell',
'echo', 'Hello World'
]
RunCommand(cmdline, verbose=False).run()
getLogger().info("Ran echo command to clear stdout and stderr")

reboot_cmd = [
adbpath,
reboot_cmd = xharness_adb() + [
'reboot'
]

wait_for_device_cmd = [
adbpath,
wait_for_device_cmd = xharness_adb() + [
'wait-for-device'
]

check_device_boot_cmd = [
adbpath,
check_device_boot_cmd = xharness_adb() + [
'shell',
'getprop',
'sys.boot_completed'
Expand Down
98 changes: 38 additions & 60 deletions src/scenarios/shared/androidhelper.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import re
import time
from performance.common import RunCommand
from logging import exception, getLogger
from logging import getLogger
from shared import const
from shared.util import xharnesscommand
from shared.util import xharness_adb, xharnesscommand

class AndroidHelper:
def __init__(self):
self.activityname = None
self.adbpath = None
self.packagename = None
self.startappcommand = None
self.stopappcommand = None
Expand All @@ -19,18 +18,20 @@ def __init__(self):
self.startscreenofftimeout = None

def setup_device(self, packagename: str, packagepath: str, animationsdisabled: bool, forcewaitstart: bool = True):
runSplitRegex = r":\s(.+)"
run_split_regex = r":\s(.+)"
self.screenwasoff = False
self.packagename = packagename
cmdline = xharnesscommand() + ['android', 'state', '--adb']
adb = RunCommand(cmdline, verbose=True)
adb.run()

# Do not remove, XHarness install seems to fail without an adb command called before the xharness command
getLogger().info("Preparing ADB")
self.adbpath = adb.stdout.strip()
cmdline = [
self.adbpath,
# Try calling xharness with stdout=None and stderr=None to hopefully bypass the hang
getLogger().info("Clearing xharness stdout and stderr to avoid hang")
cmdline = xharness_adb() + [
'shell',
'echo', 'Hello World'
]
RunCommand(cmdline, verbose=False).run()
getLogger().info("Ran echo command to clear stdout and stderr")

cmdline = xharness_adb() + [
'shell',
'wm',
'size'
Expand All @@ -39,29 +40,25 @@ def setup_device(self, packagename: str, packagepath: str, animationsdisabled: b

# Get animation values
getLogger().info("Getting Values we will need set specifically")
cmdline = [
self.adbpath,
cmdline = xharness_adb() + [
'shell', 'settings', 'get', 'global', 'window_animation_scale'
]
window_animation_scale_cmd = RunCommand(cmdline, verbose=True)
window_animation_scale_cmd.run()
self.startwindowanimationscale = window_animation_scale_cmd.stdout.strip()
cmdline = [
self.adbpath,
cmdline = xharness_adb() + [
'shell', 'settings', 'get', 'global', 'transition_animation_scale'
]
transition_animation_scale_cmd = RunCommand(cmdline, verbose=True)
transition_animation_scale_cmd.run()
self.starttransitionanimationscale = transition_animation_scale_cmd.stdout.strip()
cmdline = [
self.adbpath,
cmdline = xharness_adb() + [
'shell', 'settings', 'get', 'global', 'animator_duration_scale'
]
animator_duration_scale_cmd = RunCommand(cmdline, verbose=True)
animator_duration_scale_cmd.run()
self.startanimatordurationscale = animator_duration_scale_cmd.stdout.strip()
cmdline = [
self.adbpath,
cmdline = xharness_adb() + [
'shell', 'settings', 'get', 'system', 'screen_off_timeout'
]
screen_off_timeout_cmd = RunCommand(cmdline, verbose=True)
Expand All @@ -76,23 +73,19 @@ def setup_device(self, packagename: str, packagepath: str, animationsdisabled: b
else:
animationValue = 1
minimumTimeoutValue = 2 * 60 * 1000 # milliseconds
cmdline = [
self.adbpath,
cmdline = xharness_adb() + [
'shell', 'settings', 'put', 'global', 'window_animation_scale', str(animationValue)
]
RunCommand(cmdline, verbose=True).run()
cmdline = [
self.adbpath,
cmdline = xharness_adb() + [
'shell', 'settings', 'put', 'global', 'transition_animation_scale', str(animationValue)
]
RunCommand(cmdline, verbose=True).run()
cmdline = [
self.adbpath,
cmdline = xharness_adb() + [
'shell', 'settings', 'put', 'global', 'animator_duration_scale', str(animationValue)
]
RunCommand(cmdline, verbose=True).run()
cmdline = [
self.adbpath,
cmdline = xharness_adb() + [
'shell', 'settings', 'put', 'system', 'screen_off_timeout', str(minimumTimeoutValue)
]
if minimumTimeoutValue > int(screen_off_timeout_cmd.stdout.strip()):
Expand All @@ -101,20 +94,17 @@ def setup_device(self, packagename: str, packagepath: str, animationsdisabled: b

# Check for success
getLogger().info("Getting animation values to verify it worked")
cmdline = [
self.adbpath,
cmdline = xharness_adb() + [
'shell', 'settings', 'get', 'global', 'window_animation_scale'
]
windowSetValue = RunCommand(cmdline, verbose=True)
windowSetValue.run()
cmdline = [
self.adbpath,
cmdline = xharness_adb() + [
'shell', 'settings', 'get', 'global', 'transition_animation_scale'
]
transitionSetValue = RunCommand(cmdline, verbose=True)
transitionSetValue.run()
cmdline = [
self.adbpath,
cmdline = xharness_adb() + [
'shell', 'settings', 'get', 'global', 'animator_duration_scale'
]
animatorSetValue = RunCommand(cmdline, verbose=True)
Expand All @@ -126,8 +116,7 @@ def setup_device(self, packagename: str, packagepath: str, animationsdisabled: b
else:
getLogger().info(f"Animation values successfully set to {animationValue}.")

self.stopappcommand = [
self.adbpath,
self.stopappcommand = xharness_adb() + [
'shell',
'am',
'force-stop',
Expand All @@ -147,8 +136,7 @@ def setup_device(self, packagename: str, packagepath: str, animationsdisabled: b
RunCommand(installCmd, verbose=True).run()

getLogger().info("Completed install, running shell.")
cmdline = [
self.adbpath,
cmdline = xharness_adb() + [
'shell',
f'cmd package resolve-activity --brief {self.packagename} | tail -n 1'
]
Expand All @@ -157,16 +145,14 @@ def setup_device(self, packagename: str, packagepath: str, animationsdisabled: b
getLogger().info(f"Target Activity {getActivity.stdout}")

# More setup stuff
checkScreenOnCmd = [
self.adbpath,
checkScreenOnCmd = xharness_adb() + [
'shell',
f'dumpsys input_method | grep mInteractive'
]
checkScreenOn = RunCommand(checkScreenOnCmd, verbose=True)
checkScreenOn.run()

keyInputCmd = [
self.adbpath,
keyInputCmd = xharness_adb() + [
'shell',
'input',
'keyevent'
Expand All @@ -190,8 +176,7 @@ def setup_device(self, packagename: str, packagepath: str, animationsdisabled: b
self.activityname = getActivity.stdout.strip()

# -W in the start command waits for the app to finish initial draw.
self.startappcommand = [
self.adbpath,
self.startappcommand = xharness_adb() + [
'shell',
'am',
'start-activity',
Expand All @@ -202,7 +187,7 @@ def setup_device(self, packagename: str, packagepath: str, animationsdisabled: b

testRun = RunCommand(self.startappcommand, verbose=True)
testRun.run()
testRunStats = re.findall(runSplitRegex, testRun.stdout) # Split results saving value (List: Starting, Status, LaunchState, Activity, TotalTime, WaitTime)
testRunStats = re.findall(run_split_regex, testRun.stdout) # Split results saving value (List: Starting, Status, LaunchState, Activity, TotalTime, WaitTime)
getLogger().info(f"Test run activity: {testRunStats[3]}")
time.sleep(10) # Add delay to ensure app is fully installed and give it some time to settle

Expand All @@ -223,16 +208,15 @@ def setup_device(self, packagename: str, packagepath: str, animationsdisabled: b
# Check to make sure it worked
testRun = RunCommand(self.startappcommand, verbose=True)
testRun.run()
testRunStats = re.findall(runSplitRegex, testRun.stdout)
testRunStats = re.findall(run_split_regex, testRun.stdout)
getLogger().info(f"Test run activity: {testRunStats[3]}")
RunCommand(self.stopappcommand, verbose=True).run()

if "com.google.android.permissioncontroller" in testRunStats[3]:
getLogger().exception("Failed to get past permission screen, run locally to see if enough next button presses were used.")
raise Exception("Failed to get past permission screen, run locally to see if enough next button presses were used.")

self.startappcommand = [
self.adbpath,
self.startappcommand = xharness_adb() + [
'shell',
'am',
'start-activity'
Expand All @@ -246,8 +230,7 @@ def setup_device(self, packagename: str, packagepath: str, animationsdisabled: b
]

def close_device(self):
keyInputCmd = [
self.adbpath,
keyInputCmd = xharness_adb() + [
'shell',
'input',
'keyevent'
Expand All @@ -266,32 +249,27 @@ def close_device(self):
RunCommand(uninstallAppCmd, verbose=True).run()


keyInputCmd = [
self.adbpath,
keyInputCmd = xharness_adb() + [
'shell',
'input',
'keyevent'
]

# Reset animation values
getLogger().info("Resetting animation values to pretest values")
cmdline = [
self.adbpath,
cmdline = xharness_adb() + [
'shell', 'settings', 'put', 'global', 'window_animation_scale', self.startwindowanimationscale
]
RunCommand(cmdline, verbose=True).run()
cmdline = [
self.adbpath,
cmdline = xharness_adb() + [
'shell', 'settings', 'put', 'global', 'transition_animation_scale', self.starttransitionanimationscale
]
RunCommand(cmdline, verbose=True).run()
cmdline = [
self.adbpath,
cmdline = xharness_adb() + [
'shell', 'settings', 'put', 'global', 'animator_duration_scale', self.startanimatordurationscale
]
RunCommand(cmdline, verbose=True).run()
cmdline = [
self.adbpath,
cmdline = xharness_adb() + [
'shell', 'settings', 'put', 'system', 'screen_off_timeout', self.startscreenofftimeout
]
RunCommand(cmdline, verbose=True).run()
Expand Down
Loading
Loading