Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: DiaSession shows async methods to be external #307

Merged
merged 5 commits into from
Dec 30, 2016
Merged
Show file tree
Hide file tree
Changes from 4 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
17 changes: 16 additions & 1 deletion TestPlatform.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26009.0
VisualStudioVersion = 15.0.26005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{ED0C35EB-7F31-4841-A24F-8EB708FFA959}"
EndProject
Expand Down Expand Up @@ -118,6 +118,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PerfTestProject", "test\Tes
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleDataCollector", "test\TestAssets\SimpleDataCollector\SimpleDataCollector.csproj", "{D62D754C-8F0A-406F-8BA7-E96C6FFA7C7C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimpleTestProject3", "test\TestAssets\SimpleTestProject3\SimpleTestProject3.csproj", "{82E75225-FA92-4F87-909D-039D62F96BFF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -644,6 +646,18 @@ Global
{D62D754C-8F0A-406F-8BA7-E96C6FFA7C7C}.Release|x64.Build.0 = Release|Any CPU
{D62D754C-8F0A-406F-8BA7-E96C6FFA7C7C}.Release|x86.ActiveCfg = Release|Any CPU
{D62D754C-8F0A-406F-8BA7-E96C6FFA7C7C}.Release|x86.Build.0 = Release|Any CPU
{82E75225-FA92-4F87-909D-039D62F96BFF}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{82E75225-FA92-4F87-909D-039D62F96BFF}.Debug|Any CPU.Build.0 = Release|Any CPU
{82E75225-FA92-4F87-909D-039D62F96BFF}.Debug|x64.ActiveCfg = Release|Any CPU
{82E75225-FA92-4F87-909D-039D62F96BFF}.Debug|x64.Build.0 = Release|Any CPU
{82E75225-FA92-4F87-909D-039D62F96BFF}.Debug|x86.ActiveCfg = Release|Any CPU
{82E75225-FA92-4F87-909D-039D62F96BFF}.Debug|x86.Build.0 = Release|Any CPU
{82E75225-FA92-4F87-909D-039D62F96BFF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{82E75225-FA92-4F87-909D-039D62F96BFF}.Release|Any CPU.Build.0 = Release|Any CPU
{82E75225-FA92-4F87-909D-039D62F96BFF}.Release|x64.ActiveCfg = Release|Any CPU
{82E75225-FA92-4F87-909D-039D62F96BFF}.Release|x64.Build.0 = Release|Any CPU
{82E75225-FA92-4F87-909D-039D62F96BFF}.Release|x86.ActiveCfg = Release|Any CPU
{82E75225-FA92-4F87-909D-039D62F96BFF}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -698,5 +712,6 @@ Global
{A23E3408-D569-488E-A071-E1B3625C5F09} = {8DA7CBD9-F17E-41B6-90C4-CFF55848A25A}
{57B182B8-9014-4C6D-B966-B464DE3127D5} = {8DA7CBD9-F17E-41B6-90C4-CFF55848A25A}
{D62D754C-8F0A-406F-8BA7-E96C6FFA7C7C} = {8DA7CBD9-F17E-41B6-90C4-CFF55848A25A}
{82E75225-FA92-4F87-909D-039D62F96BFF} = {8DA7CBD9-F17E-41B6-90C4-CFF55848A25A}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,25 @@ internal static MethodDebugInformationHandle GetMethodDebugInformationHandle(Met
return handle;
}

private static void GetMethodStartAndEndLineNumber(
private static void GetMethodMinAndMaxLineNumber(
MethodDebugInformation methodDebugDefinition,
out int startLineNumber,
out int endLineNumber)
out int minLineNumber,
out int maxLineNumber)
{
var startPoint = methodDebugDefinition.GetSequencePoints().OrderBy(s => s.StartLine).FirstOrDefault();
startLineNumber = startPoint.StartLine;
var endPoint =
methodDebugDefinition.GetSequencePoints().OrderByDescending(s => s.StartLine).FirstOrDefault();
endLineNumber = endPoint.StartLine;
minLineNumber = int.MaxValue;
maxLineNumber = int.MinValue;
var orderedSequencePoints = methodDebugDefinition.GetSequencePoints();
foreach (var sequencePoint in orderedSequencePoints)
{
if (sequencePoint.IsHidden)
{
// Special sequence point with startLine is Magic number 0xFEEFEE
// Magic number comes from Potable CodeGen source code
continue;
}
minLineNumber = Math.Min(minLineNumber, sequencePoint.StartLine);
maxLineNumber = Math.Max(maxLineNumber, sequencePoint.StartLine);
}
}

/// <summary>
Expand Down Expand Up @@ -134,10 +143,10 @@ private DiaNavigationData GetDiaNavigationData(MethodDebugInformationHandle hand
{
var methodDebugDefinition = this.reader.GetMethodDebugInformation(handle);
var fileName = this.GetMethodFileName(methodDebugDefinition);
int startLineNumber, endLineNumber;
GetMethodStartAndEndLineNumber(methodDebugDefinition, out startLineNumber, out endLineNumber);
int minLineNumber, maxLineNumber;
GetMethodMinAndMaxLineNumber(methodDebugDefinition, out minLineNumber, out maxLineNumber);

diaNavigationData = new DiaNavigationData(fileName, startLineNumber, endLineNumber);
diaNavigationData = new DiaNavigationData(fileName, minLineNumber, maxLineNumber);
}
catch (BadImageFormatException exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,37 +96,33 @@ private void PopulateCacheForTypeAndMethodSymbols(string binaryPath)
// Load assembly
var asm = AssemblyLoadContext.Default.LoadFromAssemblyPath(binaryPath);

// Get all types to dict, fullname as key
var typesDict = asm.GetTypes().ToDictionary(type => type.FullName);
foreach (var typeEntry in typesDict)
foreach (var type in asm.GetTypes())
{
// Get method infos for all types in assembly
var methodInfoDict = typeEntry.Value.GetMethods().ToDictionary(methodInfo => methodInfo.Name);
// Get declared method infos
var methodInfoList = ((TypeInfo)type.GetTypeInfo()).DeclaredMethods;
var methodsNavigationData = new Dictionary<string, DiaNavigationData>();
this.methodsNavigationDataForType.Add(typeEntry.Key, methodsNavigationData);

foreach (var methodEntry in methodInfoDict)
foreach (var methodInfo in methodInfoList)
{
if (string.CompareOrdinal(methodEntry.Value.Module.FullyQualifiedName, binaryPath) != 0)
{
// Ignore inherent methods
continue;
}

var diaNavigationData = pdbReader.GetDiaNavigationData(methodEntry.Value);
var diaNavigationData = pdbReader.GetDiaNavigationData(methodInfo);
if (diaNavigationData != null)
{
methodsNavigationData.Add(methodEntry.Key, diaNavigationData);
methodsNavigationData[methodInfo.Name] = diaNavigationData;
}
else
{
EqtTrace.Error(
string.Format(
"Unable to find source information for method: {0} type: {1}",
methodEntry.Key,
typeEntry.Key));
methodInfo.Name,
type.FullName));
}
}

if (methodsNavigationData.Count != 0)
{
this.methodsNavigationDataForType[type.FullName] = methodsNavigationData;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TestPlatformRoot Condition="$(TestPlatformRoot) == ''">$(MSBuildThisFileDirectory)../../</TestPlatformRoot>
<TestProject>true</TestProject>
</PropertyGroup>

<Import Project="$(TestPlatformRoot)scripts/build/TestPlatform.Settings.targets" />

<PropertyGroup>
<OutputType Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">Exe</OutputType>
<TargetFrameworks>netcoreapp1.0;net46</TargetFrameworks>
<AssemblyName>Microsoft.TestPlatform.Common.UnitTests</AssemblyName>
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">$(PackageTargetFallback);dnxcore50;portable-net45+win8</PackageTargetFallback>
</PropertyGroup>

<ItemGroup>
<Compile Include="**\*.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.TestPlatform.Common\Microsoft.TestPlatform.Common.csproj" />
<ProjectReference Include="..\..\src\Microsoft.TestPlatform.ObjectModel\Microsoft.TestPlatform.ObjectModel.csproj">
Expand All @@ -31,26 +27,25 @@
</ProjectReference>
<ProjectReference Include="..\..\src\Microsoft.TestPlatform.CrossPlatEngine\Microsoft.TestPlatform.CrossPlatEngine.csproj" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<PackageReference Include="Microsoft.NETCore.App">
<Version>1.0.0</Version>
</PackageReference>
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
<Reference Include="System.Runtime" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Xml" />
</ItemGroup>

<ItemGroup>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this service?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VS generates this automatically, to identify it as test project. Explanation here.

<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<!-- Workaround for https://github.com/dotnet/sdk/issues/364 -->
<Target Name="WorkAroundPackageAndProjectReferenceConflict" BeforeTargets="ResolveLockFileReferences">
<ItemGroup>
<ResolvedCompileFileDefinitions Remove="@(ResolvedCompileFileDefinitions)" Condition="'%(ResolvedCompileFileDefinitions.Filename)' == 'Microsoft.TestPlatform.CoreUtilities' Or '%(ResolvedCompileFileDefinitions.Filename)' == 'Microsoft.TestPlatform.Common'" />
</ItemGroup>
</Target>

<Import Project="$(TestPlatformRoot)scripts\build\TestPlatform.targets" />
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@
<TestProject>true</TestProject>
</PropertyGroup>
<Import Project="$(TestPlatformRoot)scripts/build/TestPlatform.Settings.targets" />

<PropertyGroup>
<OutputType Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">Exe</OutputType>
<TargetFrameworks>netcoreapp1.0;net46</TargetFrameworks>
<AssemblyName>Microsoft.TestPlatform.CommunicationUtilities.UnitTests</AssemblyName>
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">$(PackageTargetFallback);dnxcore50;portable-net45+win8</PackageTargetFallback>
</PropertyGroup>

<ItemGroup>
<Compile Include="**\*.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.TestPlatform.CommunicationUtilities\Microsoft.TestPlatform.CommunicationUtilities.csproj" />
<ProjectReference Include="..\..\src\Microsoft.TestPlatform.CoreUtilities\Microsoft.TestPlatform.CoreUtilities.csproj">
Expand All @@ -28,19 +25,19 @@
<FromP2P>true</FromP2P>
</ProjectReference>
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<PackageReference Include="Microsoft.NETCore.App">
<Version>1.0.0</Version>
</PackageReference>
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
<Reference Include="System.Runtime" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Runtime.Serialization" />
</ItemGroup>

<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(TestPlatformRoot)scripts\build\TestPlatform.targets" />
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@
<TestProject>true</TestProject>
</PropertyGroup>
<Import Project="$(TestPlatformRoot)scripts/build/TestPlatform.Settings.targets" />

<PropertyGroup>
<OutputType Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">Exe</OutputType>
<TargetFrameworks>netcoreapp1.0;net46</TargetFrameworks>
<AssemblyName>Microsoft.TestPlatform.CrossPlatEngine.UnitTests</AssemblyName>
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">$(PackageTargetFallback);dnxcore50;portable-net45+win8</PackageTargetFallback>
</PropertyGroup>

<ItemGroup>
<Compile Include="**\*.cs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.TestPlatform.CrossPlatEngine\Microsoft.TestPlatform.CrossPlatEngine.csproj" />
<ProjectReference Include="..\..\src\Microsoft.TestPlatform.ObjectModel\Microsoft.TestPlatform.ObjectModel.csproj" />
Expand All @@ -28,19 +25,19 @@
<FromP2P>true</FromP2P>
</ProjectReference>
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<PackageReference Include="Microsoft.NETCore.App">
<Version>1.0.0</Version>
</PackageReference>
</PackageReference>
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
<Reference Include="System.Runtime" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Xml" />
</ItemGroup>

<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(TestPlatformRoot)scripts\build\TestPlatform.targets" />
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,44 @@ public void GetNavigationDataShouldReturnCorrectFileNameAndLineNumber()
Assert.IsNotNull(diaNavigationData, "Failed to get navigation data");
StringAssert.EndsWith(diaNavigationData.FileName, @"\SimpleTestProject\UnitTest1.cs");

Assert.AreEqual(diaNavigationData.MinLineNumber, 23);
Assert.AreEqual(diaNavigationData.MaxLineNumber, 25);
Assert.AreEqual(23, diaNavigationData.MinLineNumber, "Incorrect min line number");
Assert.AreEqual(25, diaNavigationData.MaxLineNumber, "Incorrect max line number");

this.testEnvironment.TargetFramework = currentTargetFrameWork;
}

[TestMethod]
public void GetNavigationDataShouldReturnCorrectDataForAsyncMethod()
{
var currentTargetFrameWork = GetAndSetTargetFrameWork(this.testEnvironment);
var assemblyPath = this.GetAssetFullPath("SimpleTestProject3.dll");

DiaSession diaSession = new DiaSession(assemblyPath);
DiaNavigationData diaNavigationData = diaSession.GetNavigationData("SampleUnitTestProject3.UnitTest1+<AsyncTestMethod>d__1", "MoveNext");

Assert.IsNotNull(diaNavigationData, "Failed to get navigation data");
StringAssert.EndsWith(diaNavigationData.FileName, @"\SimpleTestProject3\UnitTest1.cs");

Assert.AreEqual(20, diaNavigationData.MinLineNumber, "Incorrect min line number");
Assert.AreEqual(22, diaNavigationData.MaxLineNumber, "Incorrect max line number");

this.testEnvironment.TargetFramework = currentTargetFrameWork;
}

[TestMethod]
public void GetNavigationDataShouldReturnCorrectDataForOverLoadedMethod()
{
var currentTargetFrameWork = GetAndSetTargetFrameWork(this.testEnvironment);
var assemblyPath = this.GetAssetFullPath("SimpleTestProject3.dll");

DiaSession diaSession = new DiaSession(assemblyPath);
DiaNavigationData diaNavigationData = diaSession.GetNavigationData("SampleUnitTestProject3.Class1", "OverLoadededMethod");

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which method's navigation data should it return, there are two methods with the same name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently it is returning the last method in source file for both full and portable pdb.

Assert.IsNotNull(diaNavigationData, "Failed to get navigation data");
StringAssert.EndsWith(diaNavigationData.FileName, @"\SimpleTestProject3\UnitTest1.cs");

Assert.AreEqual(32, diaNavigationData.MinLineNumber, "Incorrect min line number");
Assert.AreEqual(33, diaNavigationData.MaxLineNumber, "Incorrect max line number");

this.testEnvironment.TargetFramework = currentTargetFrameWork;
}
Expand Down
15 changes: 5 additions & 10 deletions test/TestAssets/PerfTestProject/PerfTestProject.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />

<PropertyGroup>
<TargetFrameworks>netcoreapp1.0;net46</TargetFrameworks>
<AssemblyName>PerfTestProject</AssemblyName>
Expand All @@ -14,13 +13,11 @@
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
</PropertyGroup>

<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
<EmbeddedResource Include="compiler\resources\**\*" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk">
<Version>1.0.0-alpha-20161104-2</Version>
Expand All @@ -33,26 +30,24 @@
<Version>1.0.4-preview</Version>
</PackageReference>
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<PackageReference Include="Microsoft.NETCore.App">
<Version>1.0.0</Version>
</PackageReference>
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
<Reference Include="System.Runtime" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
<DebugType>portable</DebugType>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'net46'">
<DebugType>full</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
</PropertyGroup>

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
</Project>
Loading