public void GetDeviceToUse() { var requiredArchitecture = "x86_64"; var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); var result = runner.GetDeviceToUse(_mainLog.Object, requiredArchitecture, "architecture"); _processManager.Verify(pm => pm.Run(s_adbPath, "devices -l", TimeSpan.FromSeconds(30)), Times.Once); Assert.True(_fakeDeviceList.ContainsKey(new Tuple <string, string>(result, requiredArchitecture))); }
public ExitCode InvokeHelper(ILogger logger, string apkPackageName, string appPackagePath, string?apkRequiredArchitecture, string?deviceId, AdbRunner runner) { try { using (logger.BeginScope("Initialization and setup of APK on device")) { // Make sure the adb server is started runner.StartAdbServer(); // if call via install command device id must be set // otherwise - from test command - apkRequiredArchitecture was set by user or .apk architecture deviceId ??= apkRequiredArchitecture != null ? runner.GetDeviceToUse(logger, apkRequiredArchitecture, "architecture") : throw new ArgumentNullException("Required architecture not specified"); if (deviceId == null) { throw new Exception($"Failed to find compatible device: {apkRequiredArchitecture}"); } runner.SetActiveDevice(deviceId); // Wait till at least device(s) are ready runner.WaitForDevice(); logger.LogDebug($"Working with {runner.GetAdbVersion()}"); // If anything changed about the app, Install will fail; uninstall it first. // (we'll ignore if it's not present) // This is where mismatched architecture APKs fail. runner.UninstallApk(apkPackageName); if (runner.InstallApk(appPackagePath) != 0) { logger.LogCritical("Install failure: Test command cannot continue"); runner.UninstallApk(apkPackageName); return(ExitCode.PACKAGE_INSTALLATION_FAILURE); } runner.KillApk(apkPackageName); } return(ExitCode.SUCCESS); } catch (Exception toLog) { throw new Exception($"Failed to run test package: {toLog.Message}"); } }
protected override Task <ExitCode> InvokeInternal(ILogger logger) { if (!File.Exists(_arguments.AppPackagePath)) { logger.LogCritical($"Couldn't find {_arguments.AppPackagePath}!"); return(Task.FromResult(ExitCode.PACKAGE_NOT_FOUND)); } var runner = new AdbRunner(logger); string apkRequiredArchitecture; if (!string.IsNullOrEmpty(_arguments.DeviceArchitecture)) { apkRequiredArchitecture = _arguments.DeviceArchitecture; } else { apkRequiredArchitecture = ApkHelper.GetApkSupportedArchitectures(_arguments.AppPackagePath).First(); } try { // Make sure the adb server is started runner.StartAdbServer(); // enumerate the devices attached and their architectures // Tell ADB to only use that one (will always use the present one for systems w/ only 1 machine) var deviceToUse = runner.GetDeviceToUse(logger, apkRequiredArchitecture, "architecture"); if (deviceToUse == null) { return(Task.FromResult(ExitCode.ADB_DEVICE_ENUMERATION_FAILURE)); } Console.WriteLine(deviceToUse); return(Task.FromResult(ExitCode.SUCCESS)); } catch (Exception toLog) { logger.LogCritical(toLog, $"Failure to find compatible device: {toLog.Message}"); } return(Task.FromResult(ExitCode.GENERAL_FAILURE)); }