From 815174072529c5183fc7418bec20dce61f2f6f15 Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Wed, 15 Dec 2021 09:53:06 -0300 Subject: [PATCH] [wasm][debugger] Fix source-link test (#62786) * Fix 62551 * Addressing @radical comments. * Adding comments to not forget what we were trying to test. Indenting. --- .../debugger/BrowserDebugProxy/DebugStore.cs | 4 +-- .../wasm/debugger/DebuggerTestSuite/Tests.cs | 29 ++++++++++++++++ .../debugger-test-with-source-link.csproj | 33 +++++++++++-------- .../source-link.json | 5 +++ 4 files changed, 56 insertions(+), 15 deletions(-) create mode 100644 src/mono/wasm/debugger/tests/debugger-test-with-source-link/source-link.json diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs b/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs index 6fb9b309d88e28..e5579df8f86487 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs @@ -824,14 +824,14 @@ internal void AddMethod(MethodInfo mi) return (start.StartLocation.Line, start.StartLocation.Column, end.EndLocation.Line, end.EndLocation.Column); } - private async Task GetDataAsync(Uri uri, CancellationToken token) + private static async Task GetDataAsync(Uri uri, CancellationToken token) { var mem = new MemoryStream(); try { if (uri.IsFile && File.Exists(uri.LocalPath)) { - using (FileStream file = File.Open(SourceUri.LocalPath, FileMode.Open)) + using (FileStream file = File.Open(uri.LocalPath, FileMode.Open)) { await file.CopyToAsync(mem, token).ConfigureAwait(false); mem.Position = 0; diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/Tests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/Tests.cs index 965a55dcd534a3..66d9ec8ef418cc 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/Tests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/Tests.cs @@ -806,9 +806,38 @@ await LoadAssemblyDynamically( Assert.DoesNotContain(source_location, scripts.Values); } + [Fact] + public async Task GetSourceUsingSourceUri() + { + //testing without using sourcelink, expected values at GetSourceAsync + //SourceUri - file:///LOCAL_PATH/runtime/src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs + //SourceLinkUri - empty + var bp1_res = await SetBreakpoint("dotnet://debugger-test.dll/debugger-test.cs", 10, 8); + + Assert.EndsWith("debugger-test.cs", bp1_res.Value["breakpointId"].ToString()); + Assert.Equal(1, bp1_res.Value["locations"]?.Value()?.Count); + + var loc = bp1_res.Value["locations"]?.Value()[0]; + + var sourceToGet = JObject.FromObject(new + { + scriptId = loc["scriptId"]?.Value() + }); + + Assert.Equal("dotnet://debugger-test.dll/debugger-test.cs", scripts[loc["scriptId"]?.Value()]); + var source = await cli.SendCommand("Debugger.getScriptSource", sourceToGet, token); + Assert.True(source.IsOk); + } [Fact] public async Task GetSourceUsingSourceLink() { + //testing using sourcelink, expected values at GetSourceAsync + // On CI + //SourceUri - file:///fakepath/LOCAL_PATH/runtime/src/mono/wasm/debugger/tests/debugger-test-with-source-link/test.cs + //SourceLinkUri - file:///LOCAL_PATH/runtime/src/mono/wasm/debugger/tests/debugger-test-with-source-link/test.cs + // Locally + // SourceUri - file:////src/mono/wasm/debugger/tests/debugger-test-with-source-link/test.cs + // SourceLinkUri - https://raw.githubusercontent.com/FORK/runtime/COMMIT_ID/src/mono/wasm/debugger/tests/debugger-test-with-source-link/test.cs var bp = await SetBreakpointInMethod("debugger-test-with-source-link.dll", "DebuggerTests.ClassToBreak", "TestBreakpoint", 0); var pause_location = await EvaluateAndCheck( "window.setTimeout(function() { invoke_static_method ('[debugger-test-with-source-link] DebuggerTests.ClassToBreak:TestBreakpoint'); }, 1);", diff --git a/src/mono/wasm/debugger/tests/debugger-test-with-source-link/debugger-test-with-source-link.csproj b/src/mono/wasm/debugger/tests/debugger-test-with-source-link/debugger-test-with-source-link.csproj index 879a6ee169ec7d..a2750bd53e1215 100644 --- a/src/mono/wasm/debugger/tests/debugger-test-with-source-link/debugger-test-with-source-link.csproj +++ b/src/mono/wasm/debugger/tests/debugger-test-with-source-link/debugger-test-with-source-link.csproj @@ -1,15 +1,22 @@ - - LibraryTest - 1.0.0 - true - https://github.com/dotnet/runtime.git - git - true - true - embedded - true - true - false - + + LibraryTest + 1.0.0 + true + + + true + https://github.com/dotnet/runtime.git + git + true + true + embedded + true + false + + + source-link.json + $(MSBuildProjectDirectory)\ + $(AppOutputBase)=/fakepath/$(MSBuildProjectDirectory) + diff --git a/src/mono/wasm/debugger/tests/debugger-test-with-source-link/source-link.json b/src/mono/wasm/debugger/tests/debugger-test-with-source-link/source-link.json new file mode 100644 index 00000000000000..b2c43725600e6c --- /dev/null +++ b/src/mono/wasm/debugger/tests/debugger-test-with-source-link/source-link.json @@ -0,0 +1,5 @@ +{ + "documents": { + "/fakepath/*": "" + } +} \ No newline at end of file