Skip to content

Commit

Permalink
[wasm][debugger] Fix source-link test (dotnet#62786)
Browse files Browse the repository at this point in the history
* Fix 62551

* Addressing @radical comments.

* Adding comments to not forget what we were trying to test.
Indenting.
  • Loading branch information
thaystg authored Dec 15, 2021
1 parent e233b7b commit 8151740
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MemoryStream> GetDataAsync(Uri uri, CancellationToken token)
private static async Task<MemoryStream> 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;
Expand Down
29 changes: 29 additions & 0 deletions src/mono/wasm/debugger/DebuggerTestSuite/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<JArray>()?.Count);

var loc = bp1_res.Value["locations"]?.Value<JArray>()[0];

var sourceToGet = JObject.FromObject(new
{
scriptId = loc["scriptId"]?.Value<string>()
});

Assert.Equal("dotnet://debugger-test.dll/debugger-test.cs", scripts[loc["scriptId"]?.Value<string>()]);
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);",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackageId>LibraryTest</PackageId>
<Version>1.0.0</Version>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<RepositoryUrl>https://github.com/dotnet/runtime.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<EnableSourceLink>true</EnableSourceLink>
<IncludeSymbols>true</IncludeSymbols>
<DebugType>embedded</DebugType>
<IncludeSymbols>true</IncludeSymbols>
<DeterministicSourcePaths>true</DeterministicSourcePaths>
<DisableSourceLink>false</DisableSourceLink>
</PropertyGroup>
<PropertyGroup>
<PackageId>LibraryTest</PackageId>
<Version>1.0.0</Version>
<DeterministicSourcePaths>true</DeterministicSourcePaths>
</PropertyGroup>
<PropertyGroup Condition="'$(ContinuousIntegrationBuild)' != 'true'">
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<RepositoryUrl>https://github.com/dotnet/runtime.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<EnableSourceLink>true</EnableSourceLink>
<IncludeSymbols>true</IncludeSymbols>
<DebugType>embedded</DebugType>
<IncludeSymbols>true</IncludeSymbols>
<DisableSourceLink>false</DisableSourceLink>
</PropertyGroup>
<PropertyGroup Condition="'$(ContinuousIntegrationBuild)' == 'true'">
<SourceLink>source-link.json</SourceLink>
<AppOutputBase>$(MSBuildProjectDirectory)\</AppOutputBase>
<PathMap>$(AppOutputBase)=/fakepath/$(MSBuildProjectDirectory)</PathMap>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"documents": {
"/fakepath/*": ""
}
}

0 comments on commit 8151740

Please sign in to comment.