public ITestReporter Create(IFileBackedLog mainLog, IReadableLog runLog, ILogs logs, ICrashSnapshotReporter crashReporter, ISimpleListener simpleListener, IResultParser parser, AppBundleInformation appInformation, RunMode runMode, XmlResultJargon xmlJargon, string?device, TimeSpan timeout, string?additionalLogsDirectory = null, ExceptionLogger?exceptionLogger = null, bool generateHtml = false) => new TestReporter(_processManager, mainLog, runLog, logs, crashReporter, simpleListener, parser, appInformation, runMode, xmlJargon, device, timeout, additionalLogsDirectory, exceptionLogger, generateHtml);
public ITestReporter Create(ILog mainLog, ILog runLog, ILogs logs, ICrashSnapshotReporter crashReporter, ISimpleListener simpleListener, IResultParser parser, AppBundleInformation appInformation, RunMode runMode, XmlResultJargon xmlJargon, string device, TimeSpan timeout, string additionalLogsDirectory = null, ExceptionLogger exceptionLogger = null) { return(new TestReporter(processManager, mainLog, runLog, logs, crashReporter, simpleListener, parser, appInformation, runMode, xmlJargon, device, timeout, additionalLogsDirectory, exceptionLogger)); }
private async Task RunDeviceTests( MlaunchArguments mlaunchArguments, ICrashSnapshotReporter crashReporter, ITestReporter testReporter, ISimpleListener deviceListener, string deviceName, TimeSpan timeout, CancellationToken cancellationToken) { var deviceSystemLog = _logs.Create($"device-{deviceName}-{_helpers.Timestamp}.log", "Device log"); var deviceLogCapturer = _deviceLogCapturerFactory.Create(_mainLog, deviceSystemLog, deviceName); deviceLogCapturer.StartCapture(); try { await crashReporter.StartCaptureAsync(); // create a tunnel to communicate with the device if (_listenerFactory.UseTunnel && deviceListener is SimpleTcpListener tcpListener) { // create a new tunnel using the listener var tunnel = _listenerFactory.TunnelBore.Create(deviceName, _mainLog); tunnel.Open(deviceName, tcpListener, timeout, _mainLog); // wait until we started the tunnel await tunnel.Started; } _mainLog.WriteLine("Starting test run"); // We need to check for MT1111 (which means that mlaunch won't wait for the app to exit). var aggregatedLog = Log.CreateReadableAggregatedLog(_mainLog, testReporter.CallbackLog); var result = _processManager.ExecuteCommandAsync( mlaunchArguments, aggregatedLog, timeout, cancellationToken: cancellationToken); await testReporter.CollectDeviceResult(result); } finally { deviceLogCapturer.StopCapture(); deviceSystemLog.Dispose(); // close a tunnel if it was created if (_listenerFactory.UseTunnel) { await _listenerFactory.TunnelBore.Close(deviceName); } } // Upload the system log if (File.Exists(deviceSystemLog.FullPath)) { _mainLog.WriteLine("A capture of the device log is: {0}", deviceSystemLog.FullPath); } }
public TestReporter(IMlaunchProcessManager processManager, IFileBackedLog mainLog, IReadableLog runLog, ILogs logs, ICrashSnapshotReporter crashReporter, ISimpleListener simpleListener, IResultParser parser, AppBundleInformation appInformation, RunMode runMode, XmlResultJargon xmlJargon, string?device, TimeSpan timeout, string?additionalLogsDirectory = null, ExceptionLogger?exceptionLogger = null, bool generateHtml = false) { _processManager = processManager ?? throw new ArgumentNullException(nameof(processManager)); _deviceName = device; // can be null on simulators _listener = simpleListener ?? throw new ArgumentNullException(nameof(simpleListener)); _mainLog = mainLog ?? throw new ArgumentNullException(nameof(mainLog)); _runLog = runLog ?? throw new ArgumentNullException(nameof(runLog)); _logs = logs ?? throw new ArgumentNullException(nameof(logs)); _crashReporter = crashReporter ?? throw new ArgumentNullException(nameof(crashReporter)); _crashLogs = new Logs(logs.Directory); _resultParser = parser ?? throw new ArgumentNullException(nameof(parser)); _appInfo = appInformation ?? throw new ArgumentNullException(nameof(appInformation)); _runMode = runMode; _xmlJargon = xmlJargon; _timeout = timeout; _additionalLogsDirectory = additionalLogsDirectory; _exceptionLogger = exceptionLogger; _timeoutWatch = Stopwatch.StartNew(); _generateHtml = generateHtml; CallbackLog = new CallbackLog(line => { // MT1111: Application launched successfully, but it's not possible to wait for the app to exit as // requested because it's not possible to detect app termination when launching using gdbserver _waitedForExit &= line?.Contains("MT1111: ") != true; if (line?.Contains("error MT1007") == true) { _launchFailure = true; } }); }
public TestReporter(IProcessManager processManager, ILog mainLog, ILog runLog, ILogs logs, ICrashSnapshotReporter crashReporter, ISimpleListener simpleListener, IResultParser parser, AppBundleInformation appInformation, RunMode runMode, XmlResultJargon xmlJargon, string device, TimeSpan timeout, double launchTimeout, string additionalLogsDirectory = null, ExceptionLogger exceptionLogger = null) { this.processManager = processManager ?? throw new ArgumentNullException(nameof(processManager)); this.deviceName = device; // can be null on simulators this.listener = simpleListener ?? throw new ArgumentNullException(nameof(simpleListener)); this.mainLog = mainLog ?? throw new ArgumentNullException(nameof(mainLog)); this.runLog = runLog ?? throw new ArgumentNullException(nameof(runLog)); this.logs = logs ?? throw new ArgumentNullException(nameof(logs)); this.crashReporter = crashReporter ?? throw new ArgumentNullException(nameof(crashReporter)); this.crashLogs = new Logs(logs.Directory); this.resultParser = parser ?? throw new ArgumentNullException(nameof(parser)); this.appInfo = appInformation ?? throw new ArgumentNullException(nameof(appInformation)); this.runMode = runMode; this.xmlJargon = xmlJargon; this.timeout = timeout; this.launchTimeout = launchTimeout; this.additionalLogsDirectory = additionalLogsDirectory; this.exceptionLogger = exceptionLogger; this.timeoutWatch = Stopwatch.StartNew(); CallbackLog = new CallbackLog((line) => { // MT1111: Application launched successfully, but it's not possible to wait for the app to exit as requested because it's not possible to detect app termination when launching using gdbserver waitedForExit &= line?.Contains("MT1111: ") != true; if (line?.Contains("error MT1007") == true) { launchFailure = true; } }); }
/// <summary> /// Runs the MacCatalyst app by executing its binary (or if not found, via `open -W path.to.app`). /// </summary> private async Task <(TestExecutingResult Result, string ResultMessage)> RunMacCatalystTests( ListenerTransport deviceListenerTransport, ISimpleListener deviceListener, string deviceListenerTmpFile, AppBundleInformation appInformation, TimeSpan timeout, TimeSpan testLaunchTimeout, XmlResultJargon xmlResultJargon, string[]?skippedMethods, string[]?skippedTestClasses, CancellationToken cancellationToken) { var deviceListenerPort = deviceListener.InitializeAndGetPort(); deviceListener.StartAsync(); var crashLogs = new Logs(_logs.Directory); ICrashSnapshotReporter crashReporter = _snapshotReporterFactory.Create(_mainLog, crashLogs, isDevice: false, null); ITestReporter testReporter = _testReporterFactory.Create( _mainLog, _mainLog, _logs, crashReporter, deviceListener, _resultParser, appInformation, RunMode.MacOS, xmlResultJargon, null, timeout, null, (level, message) => _mainLog.WriteLine(message)); deviceListener.ConnectedTask .TimeoutAfter(testLaunchTimeout) .ContinueWith(testReporter.LaunchCallback) .DoNotAwait(); _mainLog.WriteLine($"*** Executing '{appInformation.AppName}' on MacCatalyst ***"); try { using var combinedCancellationToken = CancellationTokenSource.CreateLinkedTokenSource(testReporter.CancellationToken, cancellationToken); var envVariables = GetEnvVariables( xmlResultJargon, skippedMethods, skippedTestClasses, deviceListenerTransport, deviceListenerPort, deviceListenerTmpFile); envVariables[EnviromentVariables.HostName] = "127.0.0.1"; var arguments = new List <string> { "-W", appInformation.LaunchAppPath, }; arguments.AddRange(_appArguments); await crashReporter.StartCaptureAsync(); var result = await RunMacCatalystApp(appInformation, timeout, _appArguments, envVariables, combinedCancellationToken.Token); await testReporter.CollectSimulatorResult(result); } finally { deviceListener.Cancel(); deviceListener.Dispose(); } return(await testReporter.ParseResult()); }