public static void UpdateDevices <T>(Logger log, Dictionary <T, string> enumeratedDevices, Dictionary <T, ConnectedDevice> currentDevices, Action <ConnectedDevice> connectDevice) { // Stop tasks used by disconnected devices foreach (var oldDevice in currentDevices.ToArray()) { if (enumeratedDevices.ContainsKey(oldDevice.Key)) { continue; } oldDevice.Value.DeviceDisconnected = true; currentDevices.Remove(oldDevice.Key); log.Info($"Device removed: {oldDevice.Value.Name} ({oldDevice.Key})"); } // Start new devices foreach (var androidDevice in enumeratedDevices) { if (currentDevices.ContainsKey(androidDevice.Key)) { continue; } var connectedDevice = new ConnectedDevice { Key = androidDevice.Key, Name = androidDevice.Value, }; currentDevices.Add(androidDevice.Key, connectedDevice); connectDevice(connectedDevice); } }
internal Process SetupProxy(ConnectedDevice device) { var currentDir = $"{Environment.GetEnvironmentVariable("SiliconStudioXenkoDir")}\\Bin\\Windows-Direct3D11\\"; var iosId = Path.Combine(currentDir, "iproxy.exe"); int testedLocalPort; do { testedLocalPort = startLocalPort++; if (startLocalPort >= 65536) // Make sure we stay in the range of dynamic ports: 49152-65535 { startLocalPort = 49152; } } while (!CheckAvailableServerPort(testedLocalPort)); Task.Run(async() => { while (!device.DeviceDisconnected) { try { await router.TryConnect("localhost", testedLocalPort); } catch (Exception) { // Mute exceptions and try to connect again // TODO: Mute connection only, not message loop? } await Task.Delay(200); } }); var process = new Process { StartInfo = { UseShellExecute = false, CreateNoWindow = true, WorkingDirectory = currentDir, FileName = iosId, Arguments = $"{testedLocalPort} {RouterClient.DefaultListenPort} {device.Name}" } }; process.Start(); new AttachedChildProcessJob(process); Log.Info("iOS Device connected: {0}; successfully mapped port {1}:{2}", device.Name, testedLocalPort, RouterClient.DefaultListenPort); return(process); }
internal Process SetupProxy(ConnectedDevice device) { var currentDir = $"{Environment.GetEnvironmentVariable("SiliconStudioXenkoDir")}\\Bin\\Windows-Direct3D11\\"; var iosId = Path.Combine(currentDir, "iproxy.exe"); int testedLocalPort; do { testedLocalPort = startLocalPort++; if (startLocalPort >= 65536) // Make sure we stay in the range of dynamic ports: 49152-65535 startLocalPort = 49152; } while (!CheckAvailableServerPort(testedLocalPort)); Task.Run(async () => { while (!device.DeviceDisconnected) { try { await router.TryConnect("localhost", testedLocalPort); } catch (Exception) { // Mute exceptions and try to connect again // TODO: Mute connection only, not message loop? } await Task.Delay(200); } }); var process = new Process { StartInfo = { UseShellExecute = false, CreateNoWindow = true, WorkingDirectory = currentDir, FileName = iosId, Arguments = $"{testedLocalPort} {RouterClient.DefaultListenPort} {device.Name}" } }; process.Start(); new AttachedChildProcessJob(process); Log.Info("iOS Device connected: {0}; successfully mapped port {1}:{2}", device.Name, testedLocalPort, RouterClient.DefaultListenPort); return process; }
public static async Task LaunchPersistentClient(ConnectedDevice connectedDevice, Router router, string address, int localPort) { while (!connectedDevice.DeviceDisconnected) { try { await router.TryConnect(address, localPort); } catch (Exception) { // Mute exceptions and try to connect again // TODO: Mute connection only, not message loop? } await Task.Delay(200); } }
public async Task TrackDevices() { var currentDir = $"{Environment.GetEnvironmentVariable("SiliconStudioXenkoDir")}\\Bin\\Windows-Direct3D11\\"; var iosId = Path.Combine(currentDir, "idevice_id.exe"); while (true) { var thisRunDevices = new List <string>(); var process = new Process { StartInfo = { UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true, WorkingDirectory = currentDir, FileName = iosId, Arguments = "-l" } }; process.OutputDataReceived += (sender, args) => { if (args.Data.IsNullOrEmpty()) { return; } thisRunDevices.Add(args.Data); if (devices.ContainsKey(args.Data)) { return; } Log.Info(@"New iOS devices: {0}", args.Data); var newDev = new ConnectedDevice { DeviceDisconnected = false, Name = args.Data }; proxies[args.Data] = SetupProxy(newDev); devices[args.Data] = newDev; }; process.Start(); process.BeginOutputReadLine(); process.WaitForExit(); var toRemove = devices.Where(device => !thisRunDevices.Contains(device.Key)).ToList(); foreach (var device in toRemove) { device.Value.DeviceDisconnected = true; proxies[device.Key].Kill(); proxies[device.Key].WaitForExit(); proxies.Remove(device.Key); devices.Remove(device.Key); Log.Info(@"Disconnected iOS devices: {0}", device); } await Task.Delay(1000); } }
public async Task TrackDevices() { var currentDir = $"{Environment.GetEnvironmentVariable("SiliconStudioXenkoDir")}\\Bin\\Windows-Direct3D11\\"; var iosId = Path.Combine(currentDir, "idevice_id.exe"); while (true) { var thisRunDevices = new List<string>(); var process = new Process { StartInfo = { UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true, WorkingDirectory = currentDir, FileName = iosId, Arguments = "-l" } }; process.OutputDataReceived += (sender, args) => { if (args.Data.IsNullOrEmpty()) return; thisRunDevices.Add(args.Data); if (devices.ContainsKey(args.Data)) return; Log.Info(@"New iOS devices: {0}", args.Data); var newDev = new ConnectedDevice { DeviceDisconnected = false, Name = args.Data }; proxies[args.Data] = SetupProxy(newDev); devices[args.Data] = newDev; }; process.Start(); process.BeginOutputReadLine(); process.WaitForExit(); var toRemove = devices.Where(device => !thisRunDevices.Contains(device.Key)).ToList(); foreach (var device in toRemove) { device.Value.DeviceDisconnected = true; proxies[device.Key].Kill(); proxies[device.Key].WaitForExit(); proxies.Remove(device.Key); devices.Remove(device.Key); Log.Info(@"Disconnected iOS devices: {0}", device); } await Task.Delay(1000); } }
public int RunAndroidTest(ConnectedDevice device, bool reinstall, string packageName, string packageFile, string resultFilename) { resultFile = resultFilename; try { ProcessOutputs adbOutputs; var adbPath = AndroidDeviceEnumerator.GetAdbPath(); if (adbPath == null) throw new InvalidOperationException("Can't find adb"); // force stop - only works for Android 3.0 and above. ShellHelper.RunProcessAndGetOutput(adbPath, $@"-s {device.Serial} shell am force-stop {packageName}"); if (reinstall) { // uninstall ShellHelper.RunProcessAndGetOutput(adbPath, $@"-s {device.Serial} uninstall {packageName}"); // install adbOutputs = ShellHelper.RunProcessAndGetOutput(adbPath, $@"-s {device.Serial} install {packageFile}"); Console.WriteLine("adb install: exitcode {0}\nOutput: {1}\nErrors: {2}", adbOutputs.ExitCode, adbOutputs.OutputAsString, adbOutputs.ErrorsAsString); if (adbOutputs.ExitCode != 0) throw new InvalidOperationException("Invalid error code from adb install.\n Shell log: {0}"); } // run var parameters = new StringBuilder(); parameters.Append("-s "); parameters.Append(device.Serial); parameters.Append(@" shell am start -a android.intent.action.MAIN -n " + packageName + "/nunitlite.tests.MainActivity"); AddAndroidParameter(parameters, Graphics.Regression.TestRunner.XenkoVersion, XenkoVersion.CurrentAsText); AddAndroidParameter(parameters, Graphics.Regression.TestRunner.XenkoBuildNumber, buildNumber.ToString()); if (!IsNullOrEmpty(branchName)) AddAndroidParameter(parameters, Graphics.Regression.TestRunner.XenkoBranchName, branchName); Console.WriteLine(parameters.ToString()); adbOutputs = ShellHelper.RunProcessAndGetOutput(adbPath, parameters.ToString()); Console.WriteLine("adb shell am start: exitcode {0}\nOutput: {1}\nErrors: {2}", adbOutputs.ExitCode, adbOutputs.OutputAsString, adbOutputs.ErrorsAsString); if (adbOutputs.ExitCode != 0) throw new InvalidOperationException("Invalid error code from adb shell am start."); if (!clientResultsEvent.WaitOne(TimeSpan.FromSeconds(300))) //wait 30 seconds for client connection { Console.WriteLine(@"Device failed to connect."); return -1; } Console.WriteLine(@"Device client connected, waiting for test results..."); // if we receive no events during more than 5 minutes, something is wrong // we also check that test session is not finished as well while (clientResultsEvent.WaitOne(TimeSpan.FromMinutes(5)) && !testFinished) { } return testFailed ? -1 : 0; } catch (Exception e) { Console.WriteLine(@"An error was thrown when running the test on Android: {0}", e); return -1; } }