Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/mono/wasm/debugger/DebuggerTestSuite/BreakpointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.WebAssembly.Diagnostics;
using Newtonsoft.Json.Linq;
using System.IO;
using Xunit;
using System.Threading;
using Xunit.Sdk;

namespace DebuggerTests
{
Expand Down Expand Up @@ -294,11 +293,12 @@ await StepAndCheck(StepKind.Over, "dotnet://debugger-test.dll/debugger-test2.cs"
}

[Fact]
[Trait("Category", "windows-failing")] // https://github.com/dotnet/runtime/issues/62823
[Trait("Category", "linux-failing")] // https://github.com/dotnet/runtime/issues/62823
public async Task BreakpointInAssemblyUsingTypeFromAnotherAssembly_BothDynamicallyLoaded()
{
int line = 7;

// Start the task earlier than loading the assemblies, so we don't miss the event
Task<JObject> bpResolved = WaitForBreakpointResolvedEvent();
await SetBreakpoint(".*/library-dependency-debugger-test1.cs$", line, 0, use_regex: true);
await LoadAssemblyDynamically(
Path.Combine(DebuggerTestAppPath, "library-dependency-debugger-test2.dll"),
Expand All @@ -310,6 +310,8 @@ await LoadAssemblyDynamically(
var source_location = "dotnet://library-dependency-debugger-test1.dll/library-dependency-debugger-test1.cs";
Assert.Contains(source_location, scripts.Values);

await bpResolved;

var pause_location = await EvaluateAndCheck(
"window.setTimeout(function () { invoke_static_method('[library-dependency-debugger-test1] TestDependency:IntAdd', 5, 10); }, 1);",
source_location, line, 8,
Expand Down
14 changes: 14 additions & 0 deletions src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,20 @@ internal async Task<JObject> LoadAssemblyAndTestHotReload(string asm_file, strin
return await insp.WaitFor(Inspector.PAUSE);
}

public async Task<JObject> WaitForBreakpointResolvedEvent()
{
try
{
var res = await insp.WaitForEvent("Debugger.breakpointResolved");
Console.WriteLine ($"breakpoint resolved to {res}");
return res;
}
catch (TaskCanceledException)
{
throw new XunitException($"Timed out waiting for Debugger.breakpointResolved event");
}
}

internal async Task SetJustMyCode(bool enabled)
{
var req = JObject.FromObject(new { enabled = enabled });
Expand Down
28 changes: 20 additions & 8 deletions src/mono/wasm/debugger/DebuggerTestSuite/ExceptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ await CheckValue(pause_location["data"], JObject.FromObject(new
[Theory]
[InlineData("[debugger-test] DebuggerTests.ExceptionTestsClassDefault:TestExceptions", "System.Exception", 76)]
[InlineData("[debugger-test] DebuggerTests.ExceptionTestsClass:TestExceptions", "DebuggerTests.CustomException", 28)]
[Trait("Category", "linux-failing")] // https://github.com/dotnet/runtime/issues/62666
public async Task ExceptionTestAllWithReload(string entry_method_name, string class_name, int line_number)
{
var debugger_test_loc = "dotnet://debugger-test.dll/debugger-exception-test.cs";
Expand All @@ -249,14 +248,26 @@ public async Task ExceptionTestAllWithReload(string entry_method_name, string cl
}), "Page.reload",null, 0, 0, null);
Thread.Sleep(1000);

//send a lot of resumes to "skip" all the pauses on caught exception and completely reload the page
int i = 0;
while (i < 100)
// Hit resume to skip
int count = 0;
while(true)
{
Result res = await cli.SendCommand("Debugger.resume", null, token);
i++;
}
await cli.SendCommand("Debugger.resume", null, token);
count++;

try
{
await insp.WaitFor(Inspector.PAUSE)
.WaitAsync(TimeSpan.FromSeconds(10));
}
catch (TimeoutException)
{
// timed out waiting for a PAUSE
insp.ClearWaiterFor(Inspector.PAUSE);
break;
}
}
Console.WriteLine ($"* Resumed {count} times");

var eval_expr = "window.setTimeout(function() { invoke_static_method (" +
$"'{entry_method_name}'" +
Expand Down Expand Up @@ -309,7 +320,8 @@ async Task<JObject> WaitForManagedException(JObject pause_location)
AssertEqual("exception", pause_location["reason"]?.Value<string>(), $"Expected to only pause because of an exception. {pause_location}");

// return in case of a managed exception, and ignore JS ones
if (pause_location["data"]?["objectId"]?.Value<string>()?.StartsWith("dotnet:object:") == true)
if (pause_location["data"]?["objectId"]?.Value<string>()?.StartsWith("dotnet:object:", StringComparison.Ordinal) == true ||
pause_location["data"]?["uncaught"]?.Value<bool>() == true)
{
break;
}
Expand Down
18 changes: 18 additions & 0 deletions src/mono/wasm/debugger/DebuggerTestSuite/Inspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ public Task<JObject> WaitFor(string what)
}
}

public void ClearWaiterFor(string what)
{
if (notifications.ContainsKey(what))
notifications.Remove(what);
}

void NotifyOf(string what, JObject args)
{
if (notifications.TryGetValue(what, out TaskCompletionSource<JObject>? tcs))
Expand All @@ -96,6 +102,18 @@ public void On(string evtName, Func<JObject, CancellationToken, Task> cb)
eventListeners[evtName] = cb;
}

public Task<JObject> WaitForEvent(string evtName)
{
var eventReceived = new TaskCompletionSource<JObject>();
On(evtName, async (args, token) =>
{
eventReceived.SetResult(args);
await Task.CompletedTask;
});

return eventReceived.Task.WaitAsync(Token);
}

void FailAllWaiters(Exception? exception = null)
{
// Because we can create already completed tasks,
Expand Down
10 changes: 8 additions & 2 deletions src/mono/wasm/debugger/DebuggerTestSuite/MiscTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Xunit;
using Xunit.Sdk;

[assembly: CollectionBehavior(CollectionBehavior.CollectionPerAssembly)]

Expand Down Expand Up @@ -736,6 +737,7 @@ JObject FindFrame(JObject pause_location, string function_name)
[Fact]
public async Task DebugLazyLoadedAssemblyWithPdb()
{
Task<JObject> bpResolved = WaitForBreakpointResolvedEvent();
int line = 9;
await SetBreakpoint(".*/lazy-debugger-test.cs$", line, 0, use_regex: true);
await LoadAssemblyDynamically(
Expand All @@ -744,7 +746,9 @@ await LoadAssemblyDynamically(

var source_location = "dotnet://lazy-debugger-test.dll/lazy-debugger-test.cs";
Assert.Contains(source_location, scripts.Values);
System.Threading.Thread.Sleep(1000);

await bpResolved;

var pause_location = await EvaluateAndCheck(
"window.setTimeout(function () { invoke_static_method('[lazy-debugger-test] LazyMath:IntAdd', 5, 10); }, 1);",
source_location, line, 8,
Expand All @@ -755,9 +759,9 @@ await LoadAssemblyDynamically(
}

[Fact]
[Trait("Category", "linux-failing")] // https://github.com/dotnet/runtime/issues/62667
public async Task DebugLazyLoadedAssemblyWithEmbeddedPdb()
{
Task<JObject> bpResolved = WaitForBreakpointResolvedEvent();
int line = 9;
await SetBreakpoint(".*/lazy-debugger-test-embedded.cs$", line, 0, use_regex: true);
await LoadAssemblyDynamically(
Expand All @@ -767,6 +771,8 @@ await LoadAssemblyDynamically(
var source_location = "dotnet://lazy-debugger-test-embedded.dll/lazy-debugger-test-embedded.cs";
Assert.Contains(source_location, scripts.Values);

await bpResolved;

var pause_location = await EvaluateAndCheck(
"window.setTimeout(function () { invoke_static_method('[lazy-debugger-test-embedded] LazyMath:IntAdd', 5, 10); }, 1);",
source_location, line, 8,
Expand Down