Skip to content

Johluo/targeting pack tests #23045

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

Merged
merged 7 commits into from
Jun 18, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<ItemGroup>
<AssemblyAttribute Include="Microsoft.AspNetCore.TestData">
<_Parameter1>TargetingPackDependencies</_Parameter1>
<_Parameter2>@(_TargetingPackDependencies)</_Parameter2>
<_Parameter2>@(_TargetingPackDependencies->'%(FileName)')</_Parameter2>
</AssemblyAttribute>

<AspNetCoreTargetingPackDependencies
Expand Down
27 changes: 25 additions & 2 deletions src/Framework/test/SharedFxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Newtonsoft.Json.Linq;
Expand All @@ -25,11 +24,35 @@ public SharedFxTests(ITestOutputHelper output)
_expectedTfm = "net" + TestData.GetSharedFxVersion().Substring(0, 3);
_expectedRid = TestData.GetSharedFxRuntimeIdentifier();
_sharedFxRoot = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ASPNET_RUNTIME_PATH"))
? Path.Combine(TestData.GetTestDataValue("SharedFrameworkLayoutRoot"), "shared", TestData.GetTestDataValue("RuntimePackageVersion"))
? Path.Combine(TestData.GetTestDataValue("SharedFrameworkLayoutRoot"), "shared", "Microsoft.AspNetCore.App", TestData.GetTestDataValue("RuntimePackageVersion"))
: Environment.GetEnvironmentVariable("ASPNET_RUNTIME_PATH");
_expectedVersionFileName = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ASPNET_RUNTIME_PATH")) ? ".version" : "Microsoft.AspNetCore.App.versions.txt";
}

[Fact]
public void SharedFrameworkContainsListedAssemblies()
{
var actualAssemblies = Directory.GetFiles(_sharedFxRoot, "*.dll")
.Select(Path.GetFileNameWithoutExtension)
.ToHashSet();

_output.WriteLine("==== actual assemblies ====");
_output.WriteLine(string.Join('\n', actualAssemblies.OrderBy(i => i)));
_output.WriteLine("==== expected assemblies ====");
_output.WriteLine(string.Join('\n', TestData.ListedSharedFxAssemblies.OrderBy(i => i)));

var missing = TestData.ListedSharedFxAssemblies.Except(actualAssemblies);
var unexpected = actualAssemblies.Except(TestData.ListedSharedFxAssemblies);

_output.WriteLine("==== missing assemblies from the framework ====");
_output.WriteLine(string.Join('\n', missing));
_output.WriteLine("==== unexpected assemblies in the framework ====");
_output.WriteLine(string.Join('\n', unexpected));

Assert.Empty(missing);
Assert.Empty(unexpected);
}

[Fact]
public void SharedFrameworkContainsExpectedFiles()
{
Expand Down
112 changes: 109 additions & 3 deletions src/Framework/test/TargetingPackTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Reflection.Metadata;
using System.Reflection.PortableExecutable;
using System.Runtime.CompilerServices;
using Newtonsoft.Json.Linq;
using System.Xml.Linq;
using Xunit;
using Xunit.Abstractions;

Expand All @@ -18,6 +18,7 @@ namespace Microsoft.AspNetCore
public class TargetingPackTests
{
private readonly string _expectedRid;
private readonly string _targetingPackTfm;
private readonly string _targetingPackRoot;
private readonly ITestOutputHelper _output;
private readonly bool _isTargetingPackBuilding;
Expand All @@ -26,12 +27,62 @@ public TargetingPackTests(ITestOutputHelper output)
{
_output = output;
_expectedRid = TestData.GetSharedFxRuntimeIdentifier();
_targetingPackRoot = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("helix"))
_targetingPackTfm = "net" + TestData.GetSharedFxVersion().Substring(0, 3);
_targetingPackRoot = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("helix"))
? Path.Combine(TestData.GetTestDataValue("TargetingPackLayoutRoot"), "packs", "Microsoft.AspNetCore.App.Ref", TestData.GetTestDataValue("TargetingPackVersion"))
: Path.Combine(Environment.GetEnvironmentVariable("HELIX_WORKITEM_ROOT"), "Microsoft.AspNetCore.App.Ref");
_isTargetingPackBuilding = bool.Parse(TestData.GetTestDataValue("IsTargetingPackBuilding"));
}

[Fact]
public void TargetingPackContainsListedAssemblies()
{
var actualAssemblies = Directory.GetFiles(Path.Combine(_targetingPackRoot, "ref", _targetingPackTfm), "*.dll")
.Select(Path.GetFileNameWithoutExtension)
.ToHashSet();

_output.WriteLine("==== actual assemblies ====");
_output.WriteLine(string.Join('\n', actualAssemblies.OrderBy(i => i)));
_output.WriteLine("==== expected assemblies ====");
_output.WriteLine(string.Join('\n', TestData.ListedTargetingPackAssemblies.OrderBy(i => i)));

var missing = TestData.ListedTargetingPackAssemblies.Except(actualAssemblies);
var unexpected = actualAssemblies.Except(TestData.ListedTargetingPackAssemblies);

_output.WriteLine("==== missing assemblies from the framework ====");
_output.WriteLine(string.Join('\n', missing));
_output.WriteLine("==== unexpected assemblies in the framework ====");
_output.WriteLine(string.Join('\n', unexpected));

Assert.Empty(missing);
Assert.Empty(unexpected);
}

[Fact]
public void AssembliesHavePatchVersion0()
{
if (!_isTargetingPackBuilding)
{
return;
}

IEnumerable<string> dlls = Directory.GetFiles(Path.Combine(_targetingPackRoot, "ref", _targetingPackTfm), "*.dll", SearchOption.AllDirectories);
Assert.NotEmpty(dlls);

Assert.All(dlls, path =>
{
var assemblyName = AssemblyName.GetAssemblyName(path);
using var fileStream = File.OpenRead(path);
using var peReader = new PEReader(fileStream, PEStreamOptions.Default);
var reader = peReader.GetMetadataReader(MetadataReaderOptions.Default);
var assemblyDefinition = reader.GetAssemblyDefinition();

Assert.True(
assemblyDefinition.Version.Revision == 0 && assemblyDefinition.Version.Build == 0,
$"{path} has version {assemblyDefinition.Version} should have a 0.0 revision number and build number version, e.g. major.minor.0.0");
});
}

[Fact]
public void PackageOverridesContainsCorrectEntries()
{
Expand Down Expand Up @@ -75,7 +126,6 @@ public void PackageOverridesContainsCorrectEntries()
}
}


[Fact]
public void AssembliesAreReferenceAssemblies()
{
Expand Down Expand Up @@ -177,5 +227,61 @@ public void PlatformManifestListsAllFiles()
Assert.True(Version.TryParse(parts[3], out _), "File version must be convertable to System.Version");
});
}

[Fact]
public void FrameworkListListsContainsCorrectEntries()
{
if (!_isTargetingPackBuilding)
{
return;
}

var frameworkListPath = Path.Combine(_targetingPackRoot, "data", "FrameworkList.xml");
var expectedAssemblies = TestData.GetTargetingPackDependencies()
.Split(';', StringSplitOptions.RemoveEmptyEntries)
.ToHashSet();
expectedAssemblies.Remove("aspnetcorev2_inprocess");

AssertEx.FileExists(frameworkListPath);

var frameworkListDoc = XDocument.Load(frameworkListPath);
var frameworkListEntries = frameworkListDoc.Root.Descendants();

_output.WriteLine("==== file contents ====");
_output.WriteLine(string.Join('\n', frameworkListEntries.Select(i => i.Attribute("Path").Value).OrderBy(i => i)));
_output.WriteLine("==== expected assemblies ====");
_output.WriteLine(string.Join('\n', expectedAssemblies.OrderBy(i => i)));

var actualAssemblies = frameworkListEntries
.Select(i =>
{
var fileName = i.Attribute("Path").Value;
return fileName.EndsWith(".dll", StringComparison.Ordinal)
? fileName.Substring(0, fileName.Length - 4)
: fileName;
})
.ToHashSet();

var missing = expectedAssemblies.Except(actualAssemblies);
var unexpected = actualAssemblies.Except(expectedAssemblies);

_output.WriteLine("==== missing assemblies from the framework list ====");
_output.WriteLine(string.Join('\n', missing));
_output.WriteLine("==== unexpected assemblies in the framework list ====");
_output.WriteLine(string.Join('\n', unexpected));

Assert.Empty(missing);
Assert.Empty(unexpected);

Assert.All(frameworkListEntries, i =>
{
var assemblyPath = i.Attribute("Path").Value;
var assemblyVersion = i.Attribute("AssemblyVersion").Value;
var fileVersion = i.Attribute("FileVersion").Value;

Assert.True(Version.TryParse(assemblyVersion, out _), $"{assemblyPath} has assembly version {assemblyVersion}. Assembly version must be convertable to System.Version");
Assert.True(Version.TryParse(fileVersion, out _), $"{assemblyPath} has file version {fileVersion}. File version must be convertable to System.Version");
});
}
}
}
Loading