diff --git a/tests/MSBuildDeviceIntegration/Tests/DebuggingTest.cs b/tests/MSBuildDeviceIntegration/Tests/DebuggingTest.cs index ac74bd613fa..c7e4d53bc98 100755 --- a/tests/MSBuildDeviceIntegration/Tests/DebuggingTest.cs +++ b/tests/MSBuildDeviceIntegration/Tests/DebuggingTest.cs @@ -207,64 +207,69 @@ public override void OnCreate () var sw = new Stopwatch (); // setup the debugger var session = new SoftDebuggerSession (); - session.Breakpoints = new BreakpointStore (); - string file = Path.Combine (Root, b.ProjectDirectory, "MainActivity.cs"); - int line = FindTextInFile (file, "base.OnCreate (bundle);"); - session.Breakpoints.Add (file, line); - file = Path.Combine (Root, b.ProjectDirectory, "MyApplication.cs"); - line = FindTextInFile (file, "base.OnCreate ();"); - session.Breakpoints.Add (file, line); - session.TargetHitBreakpoint += (sender, e) => { - TestContext.WriteLine ($"BREAK {e.Type}, {e.Backtrace.GetFrame (0)}"); - breakcountHitCount++; - session.Continue (); - }; - var rnd = new Random (); - int port = rnd.Next (10000, 20000); - TestContext.Out.WriteLine ($"{port}"); - var args = new SoftDebuggerConnectArgs ("", IPAddress.Loopback, port) { - MaxConnectionAttempts = 2000, // we need a long delay here to get a reliable connection - }; - var startInfo = new SoftDebuggerStartInfo (args) { - WorkingDirectory = Path.Combine (b.ProjectDirectory, proj.IntermediateOutputPath, "android", "assets"), - }; - var options = new DebuggerSessionOptions () { - EvaluationOptions = EvaluationOptions.DefaultOptions, - }; - options.EvaluationOptions.UseExternalTypeResolver = true; - RunProjectAndAssert (proj, b, doNotCleanupOnUpdate: true, parameters: new string [] { - $"AndroidSdbTargetPort={port}", - $"AndroidSdbHostPort={port}", - "AndroidAttachDebugger=True", - }); - - session.LogWriter += (isStderr, text) => { Console.WriteLine (text); }; - session.OutputWriter += (isStderr, text) => { Console.WriteLine (text); }; - session.DebugWriter += (level, category, message) => { Console.WriteLine (message); }; - // do we expect the app to start? - Assert.AreEqual (activityStarts, WaitForDebuggerToStart (Path.Combine (Root, b.ProjectDirectory, "logcat.log")), "Debugger should have started"); - if (!activityStarts) - return; - Assert.False (session.HasExited, "Target should not have exited."); - session.Run (startInfo, options); - var expectedTime = TimeSpan.FromSeconds (1); - var actualTime = ProfileFor (() => session.IsConnected); - Assert.True (session.IsConnected, "Debugger should have connected but it did not."); - TestContext.Out.WriteLine ($"Debugger connected in {actualTime}"); - Assert.LessOrEqual (actualTime, expectedTime, $"Debugger should have connected within {expectedTime} but it took {actualTime}."); - // we need to wait here for a while to allow the breakpoints to hit - // but we need to timeout - TimeSpan timeout = TimeSpan.FromSeconds (60); - while (session.IsConnected && breakcountHitCount < 2 && timeout >= TimeSpan.Zero) { - Thread.Sleep (10); - timeout = timeout.Subtract (TimeSpan.FromMilliseconds (10)); + try { + session.Breakpoints = new BreakpointStore (); + string file = Path.Combine (Root, b.ProjectDirectory, "MainActivity.cs"); + int line = FindTextInFile (file, "base.OnCreate (bundle);"); + session.Breakpoints.Add (file, line); + file = Path.Combine (Root, b.ProjectDirectory, "MyApplication.cs"); + line = FindTextInFile (file, "base.OnCreate ();"); + session.Breakpoints.Add (file, line); + session.TargetHitBreakpoint += (sender, e) => { + TestContext.WriteLine ($"BREAK {e.Type}, {e.Backtrace.GetFrame (0)}"); + breakcountHitCount++; + session.Continue (); + }; + var rnd = new Random (); + int port = rnd.Next (10000, 20000); + TestContext.Out.WriteLine ($"{port}"); + var args = new SoftDebuggerConnectArgs ("", IPAddress.Loopback, port) { + MaxConnectionAttempts = 2000, // we need a long delay here to get a reliable connection + }; + var startInfo = new SoftDebuggerStartInfo (args) { + WorkingDirectory = Path.Combine (b.ProjectDirectory, proj.IntermediateOutputPath, "android", "assets"), + }; + var options = new DebuggerSessionOptions () { + EvaluationOptions = EvaluationOptions.DefaultOptions, + }; + options.EvaluationOptions.UseExternalTypeResolver = true; + RunProjectAndAssert (proj, b, doNotCleanupOnUpdate: true, parameters: new string [] { + $"AndroidSdbTargetPort={port}", + $"AndroidSdbHostPort={port}", + "AndroidAttachDebugger=True", + }); + + session.LogWriter += (isStderr, text) => { Console.WriteLine (text); }; + session.OutputWriter += (isStderr, text) => { Console.WriteLine (text); }; + session.DebugWriter += (level, category, message) => { Console.WriteLine (message); }; + // do we expect the app to start? + Assert.AreEqual (activityStarts, WaitForDebuggerToStart (Path.Combine (Root, b.ProjectDirectory, "logcat.log")), "Debugger should have started"); + if (!activityStarts) + return; + Assert.False (session.HasExited, "Target should not have exited."); + session.Run (startInfo, options); + var expectedTime = TimeSpan.FromSeconds (1); + var actualTime = ProfileFor (() => session.IsConnected); + Assert.True (session.IsConnected, "Debugger should have connected but it did not."); + TestContext.Out.WriteLine ($"Debugger connected in {actualTime}"); + Assert.LessOrEqual (actualTime, expectedTime, $"Debugger should have connected within {expectedTime} but it took {actualTime}."); + // we need to wait here for a while to allow the breakpoints to hit + // but we need to timeout + TimeSpan timeout = TimeSpan.FromSeconds (60); + while (session.IsConnected && breakcountHitCount < 2 && timeout >= TimeSpan.Zero) { + Thread.Sleep (10); + timeout = timeout.Subtract (TimeSpan.FromMilliseconds (10)); + } + WaitFor (2000); + int expected = 2; + Assert.AreEqual (expected, breakcountHitCount, $"Should have hit {expected} breakpoints. Only hit {breakcountHitCount}"); + b.BuildLogFile = "uninstall.log"; + Assert.True (b.Uninstall (proj), "Project should have uninstalled."); + } catch (Exception ex) { + Assert.Fail ($"Exception occurred {ex}"); + } finally { + session.Exit (); } - WaitFor (2000); - int expected = 2; - Assert.AreEqual (expected, breakcountHitCount, $"Should have hit {expected} breakpoints. Only hit {breakcountHitCount}"); - b.BuildLogFile = "uninstall.log"; - Assert.True (b.Uninstall (proj), "Project should have uninstalled."); - session.Exit (); } } @@ -405,93 +410,97 @@ public Foo () var sw = new Stopwatch (); // setup the debugger var session = new SoftDebuggerSession (); - - session.Breakpoints = new BreakpointStore (); - string file = Path.Combine (Root, appBuilder.ProjectDirectory, "MainActivity.cs"); - int line = FindTextInFile (file, "base.OnCreate (savedInstanceState);"); - session.Breakpoints.Add (file, line); - - file = Path.Combine (Root, appBuilder.ProjectDirectory, "MainPage.xaml.cs"); - line = FindTextInFile (file, "InitializeComponent ();"); - session.Breakpoints.Add (file, line); - - file = Path.Combine (Root, appBuilder.ProjectDirectory, "MainPage.xaml.cs"); - line = FindTextInFile (file, "Console.WriteLine ("); - session.Breakpoints.Add (file, line); - - file = Path.Combine (Root, appBuilder.ProjectDirectory, "App.xaml.cs"); - line = FindTextInFile (file, "InitializeComponent ();"); - session.Breakpoints.Add (file, line); - - file = Path.Combine (Root, libBuilder.ProjectDirectory, "Foo.cs"); - line = FindTextInFile (file, "public Foo ()"); - // Add one to the line so we get the '{' under the constructor - session.Breakpoints.Add (file, line++); - - session.TargetHitBreakpoint += (sender, e) => { - TestContext.WriteLine ($"BREAK {e.Type}, {e.Backtrace.GetFrame (0)}"); - breakcountHitCount++; - session.Continue (); - }; - var rnd = new Random (); - int port = rnd.Next (10000, 20000); - TestContext.Out.WriteLine ($"{port}"); - var args = new SoftDebuggerConnectArgs ("", IPAddress.Loopback, port) { - MaxConnectionAttempts = 2000, - }; - var startInfo = new SoftDebuggerStartInfo (args) { - WorkingDirectory = Path.Combine (appBuilder.ProjectDirectory, app.IntermediateOutputPath, "android", "assets"), - }; - var options = new DebuggerSessionOptions () { - EvaluationOptions = EvaluationOptions.DefaultOptions, - }; - options.EvaluationOptions.UseExternalTypeResolver = true; - - parameters.Add ($"AndroidSdbTargetPort={port}"); - parameters.Add ($"AndroidSdbHostPort={port}"); - parameters.Add ("AndroidAttachDebugger=True"); - - RunProjectAndAssert (app, appBuilder, doNotCleanupOnUpdate: true, parameters: parameters.ToArray ()); - - session.LogWriter += (isStderr, text) => { - TestContext.Out.WriteLine (text); - }; - session.OutputWriter += (isStderr, text) => { - TestContext.Out.WriteLine (text); - }; - session.DebugWriter += (level, category, message) => { - TestContext.Out.WriteLine (message); - }; - Assert.IsTrue (WaitForDebuggerToStart (Path.Combine (Root, appBuilder.ProjectDirectory, "logcat.log")), "Debugger should have started"); - session.Run (startInfo, options); - TestContext.Out.WriteLine ($"Detected debugger startup in log"); - Assert.False (session.HasExited, "Target should not have exited."); - WaitFor (TimeSpan.FromSeconds (30), () => session.IsConnected ); - Assert.True (session.IsConnected, "Debugger should have connected but it did not."); - // we need to wait here for a while to allow the breakpoints to hit - // but we need to timeout - TestContext.Out.WriteLine ($"Debugger connected."); - TimeSpan timeout = TimeSpan.FromSeconds (60); - int expected = 4; - while (session.IsConnected && breakcountHitCount < 3 && timeout >= TimeSpan.Zero) { - Thread.Sleep (10); - timeout = timeout.Subtract (TimeSpan.FromMilliseconds (10)); - } - WaitFor (2000); - Assert.AreEqual (expected, breakcountHitCount, $"Should have hit {expected} breakpoints. Only hit {breakcountHitCount}"); - breakcountHitCount = 0; - ClearAdbLogcat (); - ClearBlockingDialogs (); - Assert.True (ClickButton (app.PackageName, "myXFButton", "CLICK ME"), "Button should have been clicked!"); - while (session.IsConnected && breakcountHitCount < 1 && timeout >= TimeSpan.Zero) { - Thread.Sleep (10); - timeout = timeout.Subtract (TimeSpan.FromMilliseconds (10)); + try { + session.Breakpoints = new BreakpointStore (); + string file = Path.Combine (Root, appBuilder.ProjectDirectory, "MainActivity.cs"); + int line = FindTextInFile (file, "base.OnCreate (savedInstanceState);"); + session.Breakpoints.Add (file, line); + + file = Path.Combine (Root, appBuilder.ProjectDirectory, "MainPage.xaml.cs"); + line = FindTextInFile (file, "InitializeComponent ();"); + session.Breakpoints.Add (file, line); + + file = Path.Combine (Root, appBuilder.ProjectDirectory, "MainPage.xaml.cs"); + line = FindTextInFile (file, "Console.WriteLine ("); + session.Breakpoints.Add (file, line); + + file = Path.Combine (Root, appBuilder.ProjectDirectory, "App.xaml.cs"); + line = FindTextInFile (file, "InitializeComponent ();"); + session.Breakpoints.Add (file, line); + + file = Path.Combine (Root, libBuilder.ProjectDirectory, "Foo.cs"); + line = FindTextInFile (file, "public Foo ()"); + // Add one to the line so we get the '{' under the constructor + session.Breakpoints.Add (file, line++); + + session.TargetHitBreakpoint += (sender, e) => { + TestContext.WriteLine ($"BREAK {e.Type}, {e.Backtrace.GetFrame (0)}"); + breakcountHitCount++; + session.Continue (); + }; + var rnd = new Random (); + int port = rnd.Next (10000, 20000); + TestContext.Out.WriteLine ($"{port}"); + var args = new SoftDebuggerConnectArgs ("", IPAddress.Loopback, port) { + MaxConnectionAttempts = 2000, + }; + var startInfo = new SoftDebuggerStartInfo (args) { + WorkingDirectory = Path.Combine (appBuilder.ProjectDirectory, app.IntermediateOutputPath, "android", "assets"), + }; + var options = new DebuggerSessionOptions () { + EvaluationOptions = EvaluationOptions.DefaultOptions, + }; + options.EvaluationOptions.UseExternalTypeResolver = true; + + parameters.Add ($"AndroidSdbTargetPort={port}"); + parameters.Add ($"AndroidSdbHostPort={port}"); + parameters.Add ("AndroidAttachDebugger=True"); + + RunProjectAndAssert (app, appBuilder, doNotCleanupOnUpdate: true, parameters: parameters.ToArray ()); + + session.LogWriter += (isStderr, text) => { + TestContext.Out.WriteLine (text); + }; + session.OutputWriter += (isStderr, text) => { + TestContext.Out.WriteLine (text); + }; + session.DebugWriter += (level, category, message) => { + TestContext.Out.WriteLine (message); + }; + Assert.IsTrue (WaitForDebuggerToStart (Path.Combine (Root, appBuilder.ProjectDirectory, "logcat.log")), "Debugger should have started"); + session.Run (startInfo, options); + TestContext.Out.WriteLine ($"Detected debugger startup in log"); + Assert.False (session.HasExited, "Target should not have exited."); + WaitFor (TimeSpan.FromSeconds (30), () => session.IsConnected ); + Assert.True (session.IsConnected, "Debugger should have connected but it did not."); + // we need to wait here for a while to allow the breakpoints to hit + // but we need to timeout + TestContext.Out.WriteLine ($"Debugger connected."); + TimeSpan timeout = TimeSpan.FromSeconds (60); + int expected = 4; + while (session.IsConnected && breakcountHitCount < 3 && timeout >= TimeSpan.Zero) { + Thread.Sleep (10); + timeout = timeout.Subtract (TimeSpan.FromMilliseconds (10)); + } + WaitFor (2000); + Assert.AreEqual (expected, breakcountHitCount, $"Should have hit {expected} breakpoints. Only hit {breakcountHitCount}"); + breakcountHitCount = 0; + ClearAdbLogcat (); + ClearBlockingDialogs (); + Assert.True (ClickButton (app.PackageName, "myXFButton", "CLICK ME"), "Button should have been clicked!"); + while (session.IsConnected && breakcountHitCount < 1 && timeout >= TimeSpan.Zero) { + Thread.Sleep (10); + timeout = timeout.Subtract (TimeSpan.FromMilliseconds (10)); + } + expected = 1; + Assert.AreEqual (expected, breakcountHitCount, $"Should have hit {expected} breakpoints. Only hit {breakcountHitCount}"); + appBuilder.BuildLogFile = "uninstall.log"; + Assert.True (appBuilder.Uninstall (app), "Project should have uninstalled."); + } catch (Exception ex) { + Assert.Fail($"Exception occurred {ex}"); + } finally { + session.Exit (); } - expected = 1; - Assert.AreEqual (expected, breakcountHitCount, $"Should have hit {expected} breakpoints. Only hit {breakcountHitCount}"); - appBuilder.BuildLogFile = "uninstall.log"; - Assert.True (appBuilder.Uninstall (app), "Project should have uninstalled."); - session.Exit (); } } } diff --git a/tests/MSBuildDeviceIntegration/Tests/XASdkDeployTests.cs b/tests/MSBuildDeviceIntegration/Tests/XASdkDeployTests.cs index 6b02e4d3b59..7b0699af38a 100644 --- a/tests/MSBuildDeviceIntegration/Tests/XASdkDeployTests.cs +++ b/tests/MSBuildDeviceIntegration/Tests/XASdkDeployTests.cs @@ -206,6 +206,7 @@ public void SupportDesugaringStaticInterfaceMethods () [Test] [Category ("Debugger")] + [Retry(5)] public void DotNetDebug ([Values("net6.0-android", "net7.0-android")] string targetFramework) { AssertCommercialBuild (); @@ -230,52 +231,58 @@ public void DotNetDebug ([Values("net6.0-android", "net7.0-android")] string tar var sw = new Stopwatch (); // setup the debugger var session = new SoftDebuggerSession (); - session.Breakpoints = new BreakpointStore { - { Path.Combine (Root, dotnet.ProjectDirectory, "MainActivity.cs"), 10 }, - }; - session.TargetHitBreakpoint += (sender, e) => { - Console.WriteLine ($"BREAK {e.Type}"); - breakpointHit = true; - session.Continue (); - }; - var rnd = new Random (); - int port = rnd.Next (10000, 20000); - TestContext.Out.WriteLine ($"{port}"); - var args = new SoftDebuggerConnectArgs ("", IPAddress.Loopback, port) { - MaxConnectionAttempts = 10, - }; - var startInfo = new SoftDebuggerStartInfo (args) { - WorkingDirectory = Path.Combine (dotnet.ProjectDirectory, proj.IntermediateOutputPath, runtimeId, "android", "assets"), - }; - var options = new DebuggerSessionOptions () { - EvaluationOptions = EvaluationOptions.DefaultOptions, - }; - options.EvaluationOptions.UseExternalTypeResolver = true; - dotnet.BuildLogFile = Path.Combine (Root, dotnet.ProjectDirectory, "run.log"); - Assert.True (dotnet.Build ("Run", parameters: new [] { - $"AndroidSdbTargetPort={port}", - $"AndroidSdbHostPort={port}", - "AndroidAttachDebugger=True", - }), "Project should have run."); - WaitForPermissionActivity (Path.Combine (Root, dotnet.ProjectDirectory, "permission-logcat.log")); - Assert.IsTrue (WaitForDebuggerToStart (Path.Combine (Root, dotnet.ProjectDirectory, "logcat.log"), 120), "Activity should have started"); - // we need to give a bit of time for the debug server to start up. - WaitFor (2000); - session.LogWriter += (isStderr, text) => { Console.WriteLine (text); }; - session.OutputWriter += (isStderr, text) => { Console.WriteLine (text); }; - session.DebugWriter += (level, category, message) => { Console.WriteLine (message); }; - session.Run (startInfo, options); - WaitFor (TimeSpan.FromSeconds (30), () => session.IsConnected); - Assert.True (session.IsConnected, "Debugger should have connected but it did not."); - // we need to wait here for a while to allow the breakpoints to hit - // but we need to timeout - TimeSpan timeout = TimeSpan.FromSeconds (60); - while (session.IsConnected && !breakpointHit && timeout >= TimeSpan.Zero) { - Thread.Sleep (10); - timeout = timeout.Subtract (TimeSpan.FromMilliseconds (10)); + try { + session.Breakpoints = new BreakpointStore { + { Path.Combine (Root, dotnet.ProjectDirectory, "MainActivity.cs"), 10 }, + }; + session.TargetHitBreakpoint += (sender, e) => { + Console.WriteLine ($"BREAK {e.Type}"); + breakpointHit = true; + session.Continue (); + }; + var rnd = new Random (); + int port = rnd.Next (10000, 20000); + TestContext.Out.WriteLine ($"{port}"); + var args = new SoftDebuggerConnectArgs ("", IPAddress.Loopback, port) { + MaxConnectionAttempts = 10, + }; + var startInfo = new SoftDebuggerStartInfo (args) { + WorkingDirectory = Path.Combine (dotnet.ProjectDirectory, proj.IntermediateOutputPath, runtimeId, "android", "assets"), + }; + var options = new DebuggerSessionOptions () { + EvaluationOptions = EvaluationOptions.DefaultOptions, + }; + options.EvaluationOptions.UseExternalTypeResolver = true; + dotnet.BuildLogFile = Path.Combine (Root, dotnet.ProjectDirectory, "run.log"); + Assert.True (dotnet.Build ("Run", parameters: new [] { + $"AndroidSdbTargetPort={port}", + $"AndroidSdbHostPort={port}", + "AndroidAttachDebugger=True", + }), "Project should have run."); + WaitForPermissionActivity (Path.Combine (Root, dotnet.ProjectDirectory, "permission-logcat.log")); + Assert.IsTrue (WaitForDebuggerToStart (Path.Combine (Root, dotnet.ProjectDirectory, "logcat.log"), 120), "Activity should have started"); + // we need to give a bit of time for the debug server to start up. + WaitFor (2000); + session.LogWriter += (isStderr, text) => { Console.WriteLine (text); }; + session.OutputWriter += (isStderr, text) => { Console.WriteLine (text); }; + session.DebugWriter += (level, category, message) => { Console.WriteLine (message); }; + session.Run (startInfo, options); + WaitFor (TimeSpan.FromSeconds (30), () => session.IsConnected); + Assert.True (session.IsConnected, "Debugger should have connected but it did not."); + // we need to wait here for a while to allow the breakpoints to hit + // but we need to timeout + TimeSpan timeout = TimeSpan.FromSeconds (60); + while (session.IsConnected && !breakpointHit && timeout >= TimeSpan.Zero) { + Thread.Sleep (10); + timeout = timeout.Subtract (TimeSpan.FromMilliseconds (10)); + } + WaitFor (2000); + Assert.IsTrue (breakpointHit, "Should have a breakpoint"); + } catch (Exception ex) { + Assert.Fail($"Exception occurred {ex}"); + } finally { + session.Exit (); } - WaitFor (2000); - Assert.IsTrue (breakpointHit, "Should have a breakpoint"); } } }