-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable IlasmRoundTrip tests for merged tests (#93368)
* Initial work * Tweak * Tweak * Do not generate _ilasmroundtrip.py for tests that have a generated run script * Reduce imports * Force fail to see where CI fails * Revert forcing failure. Run roundtrip on build. * Trying to fix script * Backslash tweak * Do not roundtrip the same assembly * Fixing * Remove import glob * Added is_managed_assembly * remove print * Fixed paths * Support bash. Ignore certain tests for arm. Fix poison test. * Update CLRTest.Jit.targets * Feedback. Added AssemblyChecker. * Fix paths * Update src/tests/Common/Directory.Build.targets Co-authored-by: Bruce Forstall <brucefo@microsoft.com> * Feedback * Feedback * Update AssemblyChecker.csproj * Update Program.cs * Trying to fix calling python on helix. * Remove old roundtrip script calls. Added --is-exe option for AssemblyChecker. * Tweak option: * Remove check * Remove imports * Fix build * Fix syntax errors. Fixed Popen arguments * Fixed Popen arguments * Fixing debug check * Fixing tests * Update ILVerificationTests.csproj * Fixing tests * Feedback * Feedback * Update CLRTest.Jit.targets * Added help usage flag for AssemblyChecker * Feedback on assembly-checker --------- Co-authored-by: Bruce Forstall <brucefo@microsoft.com>
- Loading branch information
1 parent
1a19c09
commit cf9bb86
Showing
12 changed files
with
255 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<AssemblyName>AssemblyChecker</AssemblyName> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>$(NetCoreAppToolCurrent)</TargetFramework> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> | ||
<AppendTargetFrameworkToOutputPath Condition="'$(BuildingInsideVisualStudio)' == 'true'">true</AppendTargetFrameworkToOutputPath> | ||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> | ||
<EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<OutputPath>$(RuntimeBinDir)\AssemblyChecker</OutputPath> | ||
<RunAnalyzers>false</RunAnalyzers> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Text; | ||
using System.Diagnostics; | ||
using System.Reflection; | ||
using System.Reflection.Metadata; | ||
using System.Reflection.PortableExecutable; | ||
|
||
namespace AssemblyChecker | ||
{ | ||
/// <summary> | ||
/// This is a simple console application that is designed to answer True or False | ||
/// questions about whether a given file is a managed assembly or not. | ||
/// You can also ask whether or not the assembly is debuggable. | ||
/// Return code of 0 indicates the file is a managed assembly. | ||
/// Return code of 1 indicates the file is not a managed assembly. No errors will be printed for this one. | ||
/// </summary> | ||
public class Program | ||
{ | ||
private const string HelpText = @" | ||
Usage: | ||
<filePath>: Check if the file-path is a managed assembly. | ||
--is-debug <filePath>: Check if the file-path is a managed assembly that is built with debuggability. | ||
--is-exe <filePath>: Check if the file-path is a managed assembly that is an executable. | ||
"; | ||
|
||
static bool IsAssembly(string path) | ||
{ | ||
using var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); | ||
|
||
// Try to read CLI metadata from the PE file. | ||
using var peReader = new PEReader(fs); | ||
|
||
if (!peReader.HasMetadata) | ||
{ | ||
return false; // File does not have CLI metadata. | ||
} | ||
|
||
// Check that file has an assembly manifest. | ||
MetadataReader reader = peReader.GetMetadataReader(); | ||
return reader.IsAssembly; | ||
} | ||
|
||
static bool IsDebug(string path) | ||
{ | ||
return | ||
Assembly.LoadFrom(path) | ||
.GetCustomAttributes(typeof(DebuggableAttribute), false) | ||
.OfType<DebuggableAttribute>().Any(x => x.IsJITOptimizerDisabled); | ||
} | ||
|
||
static bool IsExe(string path) | ||
{ | ||
using var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); | ||
|
||
// Try to read CLI metadata from the PE file. | ||
using var peReader = new PEReader(fs); | ||
|
||
if (!peReader.HasMetadata) | ||
{ | ||
return false; // File does not have CLI metadata. | ||
} | ||
|
||
return peReader.PEHeaders.IsExe; | ||
} | ||
|
||
static int Main(string[] args) | ||
{ | ||
if (args.Length == 0) | ||
{ | ||
Console.WriteLine(HelpText); | ||
Console.Error.WriteLine("\nExpected assembly file-path."); | ||
return 2; | ||
} | ||
|
||
// Help | ||
if (args.Contains("-h")) | ||
{ | ||
Console.WriteLine(HelpText); | ||
return 0; | ||
} | ||
|
||
if (args.Length == 1) | ||
{ | ||
return IsAssembly(args[0]) ? 0 : 1; | ||
} | ||
|
||
if (args.Length == 2) | ||
{ | ||
switch (args[0]) | ||
{ | ||
case "--is-debug": | ||
{ | ||
return IsDebug(args[1]) ? 0 : 1; | ||
} | ||
|
||
case "--is-exe": | ||
{ | ||
return IsExe(args[1]) ? 0 : 1; | ||
} | ||
|
||
default: | ||
{ | ||
Console.WriteLine(HelpText); | ||
Console.Error.WriteLine("\nInvalid option."); | ||
return 2; | ||
} | ||
} | ||
} | ||
|
||
Console.WriteLine(HelpText); | ||
Console.Error.WriteLine("\nToo many arguments."); | ||
return 2; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.