Skip to content

Commit

Permalink
[XB1] Add more cleanup steps to test launcher (#1708)
Browse files Browse the repository at this point in the history
Add more cleanup steps to keep devices healthier over large numbers of
automated tests.

b/291640038

Change-Id: Iac9e62a4bc40faa8df8441b77a543c04e2f2196d
  • Loading branch information
TyHolc authored Oct 11, 2023
1 parent 0aef092 commit 896a0ec
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
33 changes: 25 additions & 8 deletions starboard/xb1/tools/xb1_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,16 @@
_ARGS_DIRECTORY = 'content/data/arguments'
_STARBOARD_ARGUMENTS_FILE = 'starboard_arguments.txt'
_DEFAULT_PACKAGE_NAME = 'GoogleInc.YouTube'
_STUB_PACKAGE_NAME = 'Microsoft.Title.StubApp'
_DEBUG_VC_LIBS_PACKAGE_NAME = 'Microsoft.VCLibs.140.00.Debug'
_DEFAULT_APPX_NAME = 'cobalt.appx'
_DEFAULT_STAGING_APP_NAME = 'appx'
_EXTENSION_SDK_DIR = os.path.realpath(
os.path.expandvars('%ProgramFiles(x86)%\\Microsoft SDKs'
'\\Windows Kits\\10\\ExtensionSDKs'))
_DEBUG_VC_LIBS_PATH = os.path.join(_EXTENSION_SDK_DIR, 'Microsoft.VCLibs',
'14.0', 'Appx', 'Debug', 'x64',
'Microsoft.VCLibs.x64.Debug.14.00.appx')
_XB1_LOG_FILE_PARAM = 'xb1_log_file'
_XB1_PORT = 11443
_XB1_NET_LOG_PORT = 49353
Expand Down Expand Up @@ -402,7 +410,9 @@ def UninstallSubPackages(self):
for package in packages:
try:
package_full_name = package['PackageFullName']
if package_full_name.find(_DEFAULT_PACKAGE_NAME) != -1:
if package_full_name.find(
_DEFAULT_PACKAGE_NAME) != -1 or package_full_name.find(
_STUB_PACKAGE_NAME):
if package_full_name not in uninstalled_packages:
self._LogLn('Existing YouTube app found on device. Uninstalling: ' +
package_full_name)
Expand All @@ -414,6 +424,9 @@ def UninstallSubPackages(self):
except subprocess.CalledProcessError as err:
self._LogLn(err.output)

def DeleteLooseApps(self):
self._network_api.ClearLooseAppsFiles()

def Deploy(self):
# starboard_arguments.txt is packaged with the appx. It instructs the app
# to wait for the NetArgs thread to send command-line args via the socket.
Expand All @@ -425,33 +438,37 @@ def Deploy(self):
raise IOError('Packaged appx not found in package directory. Perhaps '
'package_cobalt script did not complete successfully.')

existing_package = self.CheckPackageIsDeployed()
existing_package = self.CheckPackageIsDeployed(_DEFAULT_PACKAGE_NAME)
if existing_package:
self._LogLn('Existing YouTube app found on device. Uninstalling.')
self.WinAppDeployCmd('uninstall -package ' + existing_package)

if not self.CheckPackageIsDeployed(_DEBUG_VC_LIBS_PACKAGE_NAME):
self._LogLn('Required dependency missing. Attempting to install.')
self.WinAppDeployCmd(f'install -file "{_DEBUG_VC_LIBS_PATH}"')

self._LogLn('Deleting temporary files')
self._network_api.ClearTempFiles()

try:
self._LogLn('Installing appx file ' + appx_package_file)
self.WinAppDeployCmd('install -file ' + appx_package_file)
self.WinAppDeployCmd(f'install -file {appx_package_file}')
except subprocess.CalledProcessError:
# Install exited with non-zero status code, clear everything out, restart,
# and attempt another install.
self._LogLn('Error installing appx. Attempting a clean install...')
self.UninstallSubPackages()
self.DeleteLooseApps()
self.RestartDevkit()
self.WinAppDeployCmd('install -file ' + appx_package_file)
self.WinAppDeployCmd(f'install -file {appx_package_file}')

# Cleanup starboard arguments file.
self.InstallStarboardArgument(None)

# Validate that app was installed correctly by checking to make sure
# that the full package name can now be found.
def CheckPackageIsDeployed(self):
def CheckPackageIsDeployed(self, package_name):
package_list = self.WinAppDeployCmd('list')
package_index = package_list.find(_DEFAULT_PACKAGE_NAME)
package_index = package_list.find(package_name)
if package_index == -1:
return False
return package_list[package_index:].split('\n')[0].strip()
Expand Down Expand Up @@ -496,7 +513,7 @@ def Run(self):
else:
self._LogLn('Skipping deploy step.')

if not self.CheckPackageIsDeployed():
if not self.CheckPackageIsDeployed(_DEFAULT_PACKAGE_NAME):
raise IOError('Could not resolve ' + _DEFAULT_PACKAGE_NAME + ' to\n' +
'it\'s full package name after install! This means that' +
'\n the package is not deployed correctly!\n\n')
Expand Down
11 changes: 9 additions & 2 deletions starboard/xb1/tools/xb1_network_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

_APPX_RELATIVE_PATH = 'appx'
_DEVELOPMENT_FILES = 'DevelopmentFiles'
_LOOSE_APPS = 'LooseApps'
_LOCAL_APP_DATA = 'LocalAppData'
_LOCAL_CACHE_FOLDERNAME = r'\\LocalCache'
_TEMP_FILE_FOLDERNAME = r'\\WdpTempWebFolder'
Expand Down Expand Up @@ -561,17 +562,23 @@ def DeleteFile(self, known_folder_id, path, filename_to_delete):
'path': path
})

def ClearTempFiles(self):
def ClearDevFiles(self, path):
file_listing = self._DoJsonRequest(
'GET',
_GET_FILES_ENDPOINT,
params={
'knownfolderid': _DEVELOPMENT_FILES,
'path': _TEMP_FILE_FOLDERNAME
'path': path
})
for file in file_listing['Items']:
self.DeleteFile(_DEVELOPMENT_FILES, _TEMP_FILE_FOLDERNAME, file['Name'])

def ClearTempFiles(self):
self.ClearDevFiles(_TEMP_FILE_FOLDERNAME)

def ClearLooseAppFiles(self):
self.ClearDevFiles(_LOOSE_APPS)

def FindPackage(self, package_name):
all_packages = self.GetInstalledPackages()

Expand Down

0 comments on commit 896a0ec

Please sign in to comment.