Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 72b1fcb

Browse files
atsushikanstephentoub
authored andcommitted
Fix yet more random test failures on ILC (#19778)
* Fix yet more random test failures on ILC - FileVersionInfo.Tests TestAssembly.dll needs to exist (in its IL form) in the test directory - Fix is to mangle the file extension so that ILC treats it as a data asset rather as IL to be merged into the executable. - Other stuff is self-explanatory. * Remove checked in binary. * Fix Unix test failure. * Fix another Unix test failure.
1 parent fab6ae5 commit 72b1fcb

File tree

9 files changed

+55
-22
lines changed

9 files changed

+55
-22
lines changed

src/System.Diagnostics.FileVersionInfo/tests/System.Diagnostics.FileVersionInfo.Tests/FileVersionInfoTest.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ namespace System.Diagnostics.Tests
1010
{
1111
public partial class FileVersionInfoTest : FileCleanupTestBase
1212
{
13-
private const string TestAssemblyFileName = "System.Diagnostics.FileVersionInfo.TestAssembly.dll";
13+
// The extension is ".ildll" rather than ".dll" to prevent ILC from treating TestAssembly.dll as IL to subsume into executable.
14+
private const string TestAssemblyFileName = "System.Diagnostics.FileVersionInfo.TestAssembly.ildll";
15+
private const string OriginalTestAssemblyFileName = "System.Diagnostics.FileVersionInfo.TestAssembly.dll";
1416
private const string TestCsFileName = "Assembly1.cs";
1517
private const string TestNotFoundFileName = "notfound.dll";
1618

@@ -29,7 +31,8 @@ public void FileVersionInfo_CustomManagedAssembly()
2931
FileName = Path.Combine(Directory.GetCurrentDirectory(), TestAssemblyFileName),
3032
FilePrivatePart = 1,
3133
FileVersion = "4.3.2.1",
32-
InternalName = TestAssemblyFileName,
34+
//https://github.com/dotnet/corefx/issues/19784 InternalName different behavior on Unix.
35+
InternalName = PlatformDetection.IsWindows ? OriginalTestAssemblyFileName : TestAssemblyFileName,
3336
IsDebug = false,
3437
IsPatched = false,
3538
IsPrivateBuild = false,
@@ -38,7 +41,8 @@ public void FileVersionInfo_CustomManagedAssembly()
3841
Language = GetFileVersionLanguage(0x0000),
3942
LegalCopyright = "Copyright, you betcha!",
4043
LegalTrademarks = "TM",
41-
OriginalFilename = TestAssemblyFileName,
44+
//https://github.com/dotnet/corefx/issues/19784 OriginalFilename different behavior on Unix.
45+
OriginalFilename = PlatformDetection.IsWindows ? OriginalTestAssemblyFileName : TestAssemblyFileName,
4246
PrivateBuild = "",
4347
ProductBuildPart = 3,
4448
ProductMajorPart = 1,

src/System.Diagnostics.FileVersionInfo/tests/System.Diagnostics.FileVersionInfo.Tests/System.Diagnostics.FileVersionInfo.Tests.csproj

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
<Compile Include="$(CommonTestPath)\System\IO\FileCleanupTestBase.cs">
3131
<Link>Common\System\IO\FileCleanupTestBase.cs</Link>
3232
</Compile>
33+
<Compile Include="$(CommonTestPath)\System\PlatformDetection.cs">
34+
<Link>Common\System\PlatformDetection.cs</Link>
35+
</Compile>
3336
</ItemGroup>
3437
<ItemGroup Condition="'$(TargetsWindows)' == 'true'">
3538
<Compile Include="FileVersionInfoTest.Windows.cs" />
@@ -51,4 +54,13 @@
5154
</ProjectReference>
5255
</ItemGroup>
5356
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
54-
</Project>
57+
58+
<PropertyGroup>
59+
<BuildDependsOn>$(BuildDependsOn);MangleTestAssemblyExtension</BuildDependsOn>
60+
</PropertyGroup>
61+
<Target Name="MangleTestAssemblyExtension">
62+
<!-- Copy TestAssembly to file without .dll extension so that ILC preserves it as a data file rather than feeding it to the output executable. -->
63+
<Copy SourceFiles="$(OutputPath)\System.Diagnostics.FileVersionInfo.TestAssembly.dll" DestinationFiles="$(OutputPath)\System.Diagnostics.FileVersionInfo.TestAssembly.ildll" />
64+
</Target>
65+
66+
</Project>

src/System.Net.Primitives/tests/FunctionalTests/CookieTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public static void Value_GetSet_Success()
241241
}
242242

243243
[Fact]
244-
[SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp | TargetFrameworkMonikers.Uap)]
244+
[SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp | TargetFrameworkMonikers.Uap | TargetFrameworkMonikers.UapAot)] // Cookie.Value returns null on full framework, empty string on .NETCore
245245
public static void Value_PassNullToCtor_GetReturnsEmptyString_net46()
246246
{
247247
var cookie = new Cookie("SomeName", null);
@@ -250,7 +250,7 @@ public static void Value_PassNullToCtor_GetReturnsEmptyString_net46()
250250
}
251251

252252
[Fact]
253-
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
253+
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)] // Cookie.Value returns null on full framework, empty string on .NETCore
254254
public static void Value_PassNullToCtor_GetReturnsEmptyString()
255255
{
256256
var cookie = new Cookie("SomeName", null);

src/System.Net.Primitives/tests/FunctionalTests/LoggingTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace System.Net.Primitives.Functional.Tests
1212
public class LoggingTest : RemoteExecutorTestBase
1313
{
1414
[Fact]
15-
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "NetEventSource is only part of .NET Core")]
15+
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework | TargetFrameworkMonikers.UapAot, "NetEventSource is only part of .NET Core and requires internal Reflection")]
1616
public void EventSource_ExistsWithCorrectId()
1717
{
1818
Type esType = typeof(IPAddress).Assembly.GetType("System.Net.NetEventSource", throwOnError: true, ignoreCase: false);

src/System.Private.Xml/tests/XmlDocument/XmlAttributeCollectionTests/InsertAfterTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public void InsertAfterRemovesDupRefAttrAtTheEnd()
231231
}
232232

233233
[Fact]
234-
[SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp | TargetFrameworkMonikers.Uap)]
234+
[SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp | TargetFrameworkMonikers.Uap | TargetFrameworkMonikers.UapAot)] //Fix for this edge case was only made in NetCore
235235
public void InsertAfterThrowsArgumentOutOfRangeExceptionForDupRefAttrAtTheEnd_OldBehavior()
236236
{
237237
const string attributeName = "existingAttr";
@@ -276,7 +276,7 @@ public void InsertAfterReplacesDupRefAttr()
276276
}
277277

278278
[Fact]
279-
[SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp | TargetFrameworkMonikers.Uap)]
279+
[SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp | TargetFrameworkMonikers.Uap | TargetFrameworkMonikers.UapAot)] //Fix for this edge case was only made in NetCore
280280
public void InsertAfterDoesNotReplaceDupRefAttr_OldBehavior()
281281
{
282282
const string attributeName = "existingAttr";

src/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/System.Xml.XmlSchemaSet.Tests.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@
4040
<Compile Include="TC_SchemaSet_ValidationEventHandler.cs" />
4141
<Compile Include="TC_SchemaSet_XmlNameTable.cs" />
4242
<Compile Include="TC_SchemaSet_XmlResolver.cs" />
43+
<Compile Include="$(CommonTestPath)\System\PlatformDetection.cs">
44+
<Link>Common\System\PlatformDetection.cs</Link>
45+
</Compile>
4346
<SupplementalTestData Include="..\TestFiles\**\*.*">
4447
<Link>TestFiles\%(RecursiveDir)%(Filename)%(Extension)</Link>
4548
<DestinationDir>TestFiles\%(RecursiveDir)</DestinationDir>
4649
</SupplementalTestData>
4750
</ItemGroup>
4851
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
49-
</Project>
52+
</Project>

src/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_Misc.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,9 @@ public void Dev10_40561()
10681068
return;
10691069
}
10701070

1071+
// Test failure on ILC: Test depends on Xml Serialization and requires reflection on a LOT of types under System.Xml.Schema namespace.
1072+
// Rd.xml with "<Namespace Name="System.Xml.Schema" Dynamic="Required Public" />" lets this test pass but we should probably be
1073+
// fixing up XmlSerializer's own rd.xml rather than the test here.
10711074
[Fact]
10721075
public void GetBuiltinSimpleTypeWorksAsEcpected()
10731076
{
@@ -1256,7 +1259,10 @@ private void OnValidationEvent(object sender, ValidationEventArgs e)
12561259
CError.Compare(exception.SourceObject != null, "SourceObject == null");
12571260
return;
12581261
}
1259-
CError.Compare(exception.SourceObject.GetType().ToString(), "MS.Internal.Xml.Cache.XPathDocumentNavigator", "SourceObject.GetType");
1262+
if (!PlatformDetection.IsNetNative) // Cannot get names of internal framework types
1263+
{
1264+
CError.Compare(exception.SourceObject.GetType().ToString(), "MS.Internal.Xml.Cache.XPathDocumentNavigator", "SourceObject.GetType");
1265+
}
12601266
_output.WriteLine("Exc: " + exception);
12611267
}
12621268

src/System.Private.Xml/tests/XmlSchema/XmlSchemaValidatorApi/ExceptionVerifier.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,16 +260,21 @@ private void CompareMessages()
260260
// ignore case
261261
_expectedMessage = _expectedMessage.ToLowerInvariant();
262262
_actualMessage = _actualMessage.ToLowerInvariant();
263-
if (Regex.Match(_actualMessage, _expectedMessage, RegexOptions.Singleline).ToString() != _actualMessage)
263+
264+
265+
if (!PlatformDetection.IsNetNative) // .Net Native toolchain optimizes away Exception messages
264266
{
265-
// Unescape before printing the expected message string
266-
_expectedMessage = Regex.Unescape(_expectedMessage);
267-
_output.WriteLine("Mismatch in error message");
268-
_output.WriteLine("===== Expected Message =====\n" + _expectedMessage);
269-
_output.WriteLine("===== Expected Message Length =====\n" + _expectedMessage.Length);
270-
_output.WriteLine("===== Actual Message =====\n" + _actualMessage);
271-
_output.WriteLine("===== Actual Message Length =====\n" + _actualMessage.Length);
272-
throw new VerifyException("Mismatch in error message");
267+
if (Regex.Match(_actualMessage, _expectedMessage, RegexOptions.Singleline).ToString() != _actualMessage)
268+
{
269+
// Unescape before printing the expected message string
270+
_expectedMessage = Regex.Unescape(_expectedMessage);
271+
_output.WriteLine("Mismatch in error message");
272+
_output.WriteLine("===== Expected Message =====\n" + _expectedMessage);
273+
_output.WriteLine("===== Expected Message Length =====\n" + _expectedMessage.Length);
274+
_output.WriteLine("===== Actual Message =====\n" + _actualMessage);
275+
_output.WriteLine("===== Actual Message Length =====\n" + _actualMessage.Length);
276+
throw new VerifyException("Mismatch in error message");
277+
}
273278
}
274279
}
275280

@@ -396,4 +401,4 @@ public VerifyException(string msg)
396401
: base(msg)
397402
{ }
398403
}
399-
}
404+
}

src/System.Private.Xml/tests/XmlSchema/XmlSchemaValidatorApi/System.Xml.XmlSchema.XmlSchemaValidatorApi.Tests.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@
2727
<Compile Include="ValidatorModule.cs" />
2828
<Compile Include="XmlTestSettings.cs" />
2929
<Compile Include="CXmlTestResolver.cs" />
30+
<Compile Include="$(CommonTestPath)\System\PlatformDetection.cs">
31+
<Link>Common\System\PlatformDetection.cs</Link>
32+
</Compile>
3033
<SupplementalTestData Include="..\TestFiles\**\*.*">
3134
<Link>TestFiles\%(RecursiveDir)%(Filename)%(Extension)</Link>
3235
<DestinationDir>TestFiles\%(RecursiveDir)</DestinationDir>
3336
</SupplementalTestData>
3437
</ItemGroup>
3538
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
36-
</Project>
39+
</Project>

0 commit comments

Comments
 (0)