From 8dd89519ed705a128d85aa953c33d30ce22bf39b Mon Sep 17 00:00:00 2001 From: TIHan Date: Wed, 11 Oct 2023 14:52:46 -0700 Subject: [PATCH 01/41] Initial work --- .../Common/CLRTest.Execute.Batch.targets | 2 - src/tests/Common/CLRTest.Jit.targets | 54 +++++++++++++++++++ src/tests/run.py | 16 ++++++ 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/src/tests/Common/CLRTest.Execute.Batch.targets b/src/tests/Common/CLRTest.Execute.Batch.targets index 90ba71856b72e..e557292f4114e 100644 --- a/src/tests/Common/CLRTest.Execute.Batch.targets +++ b/src/tests/Common/CLRTest.Execute.Batch.targets @@ -470,8 +470,6 @@ IF NOT "%__TestEnv%"=="" ( $(BatchCLRTestEnvironmentCompatibilityCheck) -$(IlasmRoundTripBatchScript) - $(SuperPMICollectionBatchScript) REM Allow test environment variables or precommands to override the ExePath diff --git a/src/tests/Common/CLRTest.Jit.targets b/src/tests/Common/CLRTest.Jit.targets index 9748b6424f737..9e551496a629c 100644 --- a/src/tests/Common/CLRTest.Jit.targets +++ b/src/tests/Common/CLRTest.Jit.targets @@ -365,6 +365,60 @@ set DOTNET_JitPath=%CORE_ROOT%\superpmi-shim-collector.dll + + + + + $(AssemblyName).dll + IL-RT/$(AssemblyName).il + IL-RT/$(AssemblyName).dll + <_IlasmRoundTripScriptText> + + + + - + $(AssemblyName).dll IL-RT/$(AssemblyName).il From c59ea7d19eeb4884c569d7e9439af9c79a80e3cf Mon Sep 17 00:00:00 2001 From: TIHan Date: Wed, 11 Oct 2023 16:03:42 -0700 Subject: [PATCH 05/41] Reduce imports --- src/tests/Common/CLRTest.Jit.targets | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/tests/Common/CLRTest.Jit.targets b/src/tests/Common/CLRTest.Jit.targets index 989dc99025edf..a6ef93cd4f055 100644 --- a/src/tests/Common/CLRTest.Jit.targets +++ b/src/tests/Common/CLRTest.Jit.targets @@ -377,18 +377,10 @@ set DOTNET_JitPath=%CORE_ROOT%\superpmi-shim-collector.dll IL-RT/$(AssemblyName).il IL-RT/$(AssemblyName).dll <_IlasmRoundTripScriptText> Date: Thu, 12 Oct 2023 10:10:43 -0700 Subject: [PATCH 06/41] Force fail to see where CI fails --- src/tests/JIT/Regression/JitBlue/Runtime_92590/Runtime_92590.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_92590/Runtime_92590.cs b/src/tests/JIT/Regression/JitBlue/Runtime_92590/Runtime_92590.cs index 99a5ef2ee5d18..4ada1186e0b76 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_92590/Runtime_92590.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_92590/Runtime_92590.cs @@ -31,6 +31,7 @@ public static void TestEntryPoint() TestIntInt(ref i, 0, Vector256.Create(1)); Assert.Equal(2, i); + throw new Exception("FORCE FAIL"); } [MethodImpl(MethodImplOptions.NoInlining)] From 20adfcddf89a115ebd899332cca7d6e1272d0c77 Mon Sep 17 00:00:00 2001 From: TIHan Date: Thu, 12 Oct 2023 12:07:47 -0700 Subject: [PATCH 07/41] Revert forcing failure. Run roundtrip on build. --- src/tests/Common/CLRTest.Jit.targets | 1 + .../JitBlue/Runtime_92590/Runtime_92590.cs | 1 - src/tests/run.py | 15 --------------- 3 files changed, 1 insertion(+), 16 deletions(-) diff --git a/src/tests/Common/CLRTest.Jit.targets b/src/tests/Common/CLRTest.Jit.targets index a6ef93cd4f055..68dfb5bb5b150 100644 --- a/src/tests/Common/CLRTest.Jit.targets +++ b/src/tests/Common/CLRTest.Jit.targets @@ -409,6 +409,7 @@ except: File="$(OutputPath)\$(AssemblyName)_ilasmroundtrip.py" Lines="$(_IlasmRoundTripScriptText)" Overwrite="true" /> + - + $(AssemblyName).dll IL-RT/$(AssemblyName).il @@ -381,35 +386,46 @@ import os import shutil import subprocess import sys +import glob + +print("") +print("ILASM RoundTrips") if not os.path.exists("IL-RT"): os.mkdir("IL-RT") -shutil.copyfile("$(InputAssemblyName)", "$(TargetAssemblyName)") +for inputAssemblyName in glob.glob(r"$(OutputPath)*.dll"): + print("ILASM RoundTrip for " + inputAssemblyName) + + disassemblyName = os.path.join(r"$(OutputPath)\", "IL-RT", os.path.splitext(os.path.basename(inputAssemblyName))[0] + ".il") + targetAssemblyName = os.path.join(r"$(OutputPath)\", "IL-RT", os.path.basename(inputAssemblyName)) + + shutil.copyfile(inputAssemblyName, targetAssemblyName) + + proc = subprocess.Popen(os.environ["CORE_ROOT"] + "/ildasm /raweh /unicode /out=" + disassemblyName + " " + targetAssemblyName) -proc = subprocess.Popen(os.environ["CORE_ROOT"] + "/ildasm /raweh /unicode /out=$(DisassemblyName) $(TargetAssemblyName)") + try: + proc.communicate() + except: + proc.kill() + sys.exit(1) -try: - proc.communicate() -except: - proc.kill() - sys.exit(1) + proc = subprocess.Popen(os.environ["CORE_ROOT"] + "/ilasm /DLL /output=" + inputAssemblyName + " $(_IlasmSwitches) " + disassemblyName) -proc = subprocess.Popen(os.environ["CORE_ROOT"] + "/ilasm /output=$(InputAssemblyName) $(_IlasmSwitches) $(DisassemblyName) /DLL") + try: + proc.communicate() + except: + proc.kill() + sys.exit(1) -try: - proc.communicate() -except: - proc.kill() - sys.exit(1) +print("") ]]> - + <_jitToolsRidPlatformIndex>$(OutputRID.LastIndexOf('-')) + $(OutputRID.Substring(0, $(_jitToolsRidPlatformIndex))) + $(OutputRID.Substring($(_jitToolsRidPlatformIndex)).TrimStart('-')) + + + linux + + + x64 + arm64 + $(JITToolsRidWithoutPlatform)-$(JITToolsRidPlatform) + + $(runtimelinuxarm64MicrosoftNETCoreRuntimeJITToolsVersion) + $(runtimelinuxx64MicrosoftNETCoreRuntimeJITToolsVersion) + $(runtimelinuxmuslarm64MicrosoftNETCoreRuntimeJITToolsVersion) + $(runtimelinuxmuslx64MicrosoftNETCoreRuntimeJITToolsVersion) + $(runtimewinarm64MicrosoftNETCoreRuntimeJITToolsVersion) + $(runtimewinx64MicrosoftNETCoreRuntimeJITToolsVersion) + $(runtimeosxarm64MicrosoftNETCoreRuntimeJITToolsVersion) + $(runtimeosxx64MicrosoftNETCoreRuntimeJITToolsVersion) + + + + + + [$(JITToolsVersion)] + + + + + + + + + + + diff --git a/src/coreclr/tools/AssemblyChecker/Program.cs b/src/coreclr/tools/AssemblyChecker/Program.cs new file mode 100644 index 0000000000000..8bd3052ee8de8 --- /dev/null +++ b/src/coreclr/tools/AssemblyChecker/Program.cs @@ -0,0 +1,116 @@ +// 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.Metadata; +using System.Reflection.PortableExecutable; + +namespace AssemblyChecker +{ + public class Program + { + 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 HasDebuggableAttribute(MetadataReader reader, EntityHandle entity) + { + if (entity.IsNil) + return false; + + switch (entity.Kind) + { + case HandleKind.MemberReference: + { + var memRef = reader.GetMemberReference((MemberReferenceHandle)entity); + switch (memRef.Parent.Kind) + { + case HandleKind.TypeReference: + { + var tyRef = reader.GetTypeReference((TypeReferenceHandle)memRef.Parent); + return reader.GetString(tyRef.Name) == "DebuggableAttribute"; + } + + default: + return false; + } + } + + default: + return false; + } + + } + + static bool IsDebug(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(); + + var attrs = reader.GetAssemblyDefinition().GetCustomAttributes(); + return attrs.Any(x => HasDebuggableAttribute(reader, reader.GetCustomAttribute(x).Constructor)); + } + + static int Main(string[] args) + { + if (args.Length == 0) + { + throw new ArgumentException("Expected assembly file-path."); + } + + if (args.Length > 2) + { + throw new ArgumentException("Too many arguments."); + } + + if (args.Length == 1) + { + if (IsAssembly(args[0])) + return 0; + else + return 1; + } + + if (args.Length == 2) + { + if (args[0] == "--is-debug") + { + if (IsDebug(args[1])) + return 0; + else + return 1; + } + else + { + throw new ArgumentException("Invalid option."); + } + } + + return -1; + } + } +} diff --git a/src/tests/Common/CLRTest.Jit.targets b/src/tests/Common/CLRTest.Jit.targets index f2a9b88529cdb..def0a62f0ecca 100644 --- a/src/tests/Common/CLRTest.Jit.targets +++ b/src/tests/Common/CLRTest.Jit.targets @@ -394,54 +394,24 @@ import struct import platform def is_managed_assembly(file): - file_size = os.path.getsize(file) + proc = subprocess.Popen(dotnet f'{os.environ["CORE_ROOT"]}/AssemblyChecker/AssemblyChecker.dll {file}') - if file_size < 64: + try: + proc.communicate() + return proc.returncode == 0 + except: + proc.kill() return False - with open(file, "rb") as f: - f.seek(0x3c) +def is_managed_debug_assembly(file): + proc = subprocess.Popen(dotnet f'{os.environ["CORE_ROOT"]}/AssemblyChecker/AssemblyChecker.dll --is-debug {file}') - # PE Header starts @ 0x3C (60). Its a 4 byte header. - peHeaderPointer = struct.unpack('I', f.read(4))[0] - if peHeaderPointer == 0: - peHeaderPointer = 0x80 - - # Ensure there is at least enough room for the following structures: - # 24 byte PE Signature & Header - # 28 byte Standard Fields (24 bytes for PE32+) - # 68 byte NT Fields (88 bytes for PE32+) - # >= 128 byte Data Dictionary Table - if peHeaderPointer > (file_size - 256): - return False - - # Check the PE signature. Should equal 'PE\0\0'. - f.seek(peHeaderPointer) - peHeaderSignature = struct.unpack('I', f.read(4))[0] - if peHeaderSignature != 0x00004550: - return False - - # skip over the PEHeader fields - f.seek(f.tell() + 20) - - PE32 = 0x10b - PE32Plus = 0x20b - - # Read PE magic number from Standard Fields to determine format. - peFormat = struct.unpack('H', f.read(2))[0] - if peFormat != PE32 and peFormat != PE32Plus: - return False - - # Read the 15th Data Dictionary RVA field which contains the CLI header RVA. - # When this is non-zero then the file contains CLI data otherwise not. - dataDictionaryStart = (peHeaderPointer + (232 if peFormat == PE32 else 248)) & 0xffff - f.seek(dataDictionaryStart) - - cliHeaderRva = struct.unpack('I', f.read(4))[0] - if cliHeaderRva == 0: - return False - - return True + try: + proc.communicate() + return proc.returncode == 0 + except: + proc.kill() + return False print("") print("ILASM RoundTrips") @@ -449,28 +419,14 @@ print("ILASM RoundTrips") if not os.path.exists("IL-RT"): os.mkdir("IL-RT") -if "arm" in platform.machine(): - # TODO: Fix these roundtrip assemblies from failing on ARM64 when executing. - assembliesToIgnore = [ - "value_numbering_checked_arithmetic_with_constants_ro.dll", - "ldc_mul_ovf_i4.dll", - "overflow02_mul.dll", - "b25815.dll", - "b71869.dll" - ] -else: - assembliesToIgnore = [] - for inputAssemblyName in glob.glob("*.dll"): + # Roundtrips library assemblies. Executable assemblies are done in the bash/batch scripts. + # We filter out the executable assembly that this script gets generated from. if (not inputAssemblyName.endswith("$(AssemblyName).dll")) and is_managed_assembly(inputAssemblyName): - if inputAssemblyName not in assembliesToIgnore: print("ILASM RoundTrip for " + inputAssemblyName) ilasmSwitches = "" - - # HACK: The 'poison.csproj' is the only project that needs to be built with the debug flag. - # We do this here because we cannot easily determine whether or not it was actually built with the flag or not. - if inputAssemblyName.endswith("poison.dll"): + if is_managed_debug_assembly(file): ilasmSwitches = "-DEBUG" disassemblyName = os.path.join("IL-RT", os.path.splitext(os.path.basename(inputAssemblyName))[0] + ".il") @@ -478,7 +434,7 @@ for inputAssemblyName in glob.glob("*.dll"): shutil.copyfile(inputAssemblyName, targetAssemblyName) - proc = subprocess.Popen(os.environ["CORE_ROOT"] + "/ildasm /raweh /unicode /out=" + disassemblyName + " " + targetAssemblyName) + proc = subprocess.Popen(f'{os.environ["CORE_ROOT"]}/ildasm /raweh /unicode /out={disassemblyName} {targetAssemblyName}') try: proc.communicate() @@ -486,7 +442,7 @@ for inputAssemblyName in glob.glob("*.dll"): proc.kill() sys.exit(1) - proc = subprocess.Popen(os.environ["CORE_ROOT"] + "/ilasm /DLL /output=" + inputAssemblyName + " " + ilasmSwitches + " " + disassemblyName) + proc = subprocess.Popen(f'{os.environ["CORE_ROOT"]}/ilasm /DLL /output={inputAssemblyName} {ilasmSwitches} {disassemblyName}') try: proc.communicate() diff --git a/src/tests/Common/Directory.Build.targets b/src/tests/Common/Directory.Build.targets index 5c2707ed55408..8e4d5202f13dc 100644 --- a/src/tests/Common/Directory.Build.targets +++ b/src/tests/Common/Directory.Build.targets @@ -113,6 +113,11 @@ True + + + True + + From b06879ab0c1d08671d193f25a9b34a5457b0714e Mon Sep 17 00:00:00 2001 From: TIHan Date: Mon, 16 Oct 2023 17:26:03 -0700 Subject: [PATCH 19/41] Fix paths --- src/tests/Common/CLRTest.Jit.targets | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tests/Common/CLRTest.Jit.targets b/src/tests/Common/CLRTest.Jit.targets index c0eb3dd587008..894434ad1434a 100644 --- a/src/tests/Common/CLRTest.Jit.targets +++ b/src/tests/Common/CLRTest.Jit.targets @@ -393,7 +393,7 @@ import struct import platform def is_managed_assembly(file): - proc = subprocess.Popen(dotnet f'{os.environ["CORE_ROOT"]}/AssemblyChecker/AssemblyChecker.dll {file}') + proc = subprocess.Popen(f'{os.environ["CORE_ROOT"]}/corerun {os.environ["CORE_ROOT"]}/AssemblyChecker/AssemblyChecker.dll {file}') try: proc.communicate() @@ -403,7 +403,7 @@ def is_managed_assembly(file): return False def is_managed_debug_assembly(file): - proc = subprocess.Popen(dotnet f'{os.environ["CORE_ROOT"]}/AssemblyChecker/AssemblyChecker.dll --is-debug {file}') + proc = subprocess.Popen(f'{os.environ["CORE_ROOT"]}/corerun {os.environ["CORE_ROOT"]}/AssemblyChecker/AssemblyChecker.dll --is-debug {file}') try: proc.communicate() @@ -425,7 +425,7 @@ for inputAssemblyName in glob.glob("*.dll"): print("ILASM RoundTrip for " + inputAssemblyName) ilasmSwitches = "" - if is_managed_debug_assembly(file): + if is_managed_debug_assembly(inputAssemblyName): ilasmSwitches = "-DEBUG" disassemblyName = os.path.join("IL-RT", os.path.splitext(os.path.basename(inputAssemblyName))[0] + ".il") From 9f8d9e8fccc4fd092dc91e078093356c5d8b40c1 Mon Sep 17 00:00:00 2001 From: Will Smith Date: Tue, 17 Oct 2023 11:53:59 -0700 Subject: [PATCH 20/41] Update src/tests/Common/Directory.Build.targets Co-authored-by: Bruce Forstall --- src/tests/Common/Directory.Build.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/Common/Directory.Build.targets b/src/tests/Common/Directory.Build.targets index 8e4d5202f13dc..1e8e7f8239981 100644 --- a/src/tests/Common/Directory.Build.targets +++ b/src/tests/Common/Directory.Build.targets @@ -113,7 +113,7 @@ True - + True From 9b7bf31c0e78ec323c2c6a446de6562bc3456e8d Mon Sep 17 00:00:00 2001 From: TIHan Date: Tue, 17 Oct 2023 12:02:18 -0700 Subject: [PATCH 21/41] Feedback --- src/coreclr/tools/AssemblyChecker/Program.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/coreclr/tools/AssemblyChecker/Program.cs b/src/coreclr/tools/AssemblyChecker/Program.cs index 8bd3052ee8de8..a98a511afb77a 100644 --- a/src/coreclr/tools/AssemblyChecker/Program.cs +++ b/src/coreclr/tools/AssemblyChecker/Program.cs @@ -1,6 +1,10 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +// This is a simple console application that is designed to answer True or False +// questions about whether a give file is a managed assembly or not. +// You can also ask whether or not the assembly is debuggable. + using System.Text; using System.Diagnostics; using System.Reflection.Metadata; @@ -79,12 +83,8 @@ static int Main(string[] args) { if (args.Length == 0) { - throw new ArgumentException("Expected assembly file-path."); - } - - if (args.Length > 2) - { - throw new ArgumentException("Too many arguments."); + Console.Error.WriteLine("Expected assembly file-path."); + return 2; } if (args.Length == 1) @@ -106,11 +106,13 @@ static int Main(string[] args) } else { - throw new ArgumentException("Invalid option."); + Console.Error.WriteLine("Invalid option."); + return 2; } } - return -1; + Console.Error.WriteLine("Too many arguments."); + return 2; } } } From 0b14d9802fc4b670043585b8af7b4c4c192db56d Mon Sep 17 00:00:00 2001 From: TIHan Date: Tue, 17 Oct 2023 12:04:42 -0700 Subject: [PATCH 22/41] Feedback --- src/coreclr/tools/AssemblyChecker/Program.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/coreclr/tools/AssemblyChecker/Program.cs b/src/coreclr/tools/AssemblyChecker/Program.cs index a98a511afb77a..a8bc45ff50b86 100644 --- a/src/coreclr/tools/AssemblyChecker/Program.cs +++ b/src/coreclr/tools/AssemblyChecker/Program.cs @@ -4,6 +4,8 @@ // This is a simple console application that is designed to answer True or False // questions about whether a give 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. using System.Text; using System.Diagnostics; From 7aca653085786d8089c320d935d2793ff5429353 Mon Sep 17 00:00:00 2001 From: Will Smith Date: Tue, 17 Oct 2023 12:05:38 -0700 Subject: [PATCH 23/41] Update AssemblyChecker.csproj --- .../AssemblyChecker/AssemblyChecker.csproj | 42 ------------------- 1 file changed, 42 deletions(-) diff --git a/src/coreclr/tools/AssemblyChecker/AssemblyChecker.csproj b/src/coreclr/tools/AssemblyChecker/AssemblyChecker.csproj index 754475cb6af41..821c47c95403c 100644 --- a/src/coreclr/tools/AssemblyChecker/AssemblyChecker.csproj +++ b/src/coreclr/tools/AssemblyChecker/AssemblyChecker.csproj @@ -13,46 +13,4 @@ $(RuntimeBinDir)\AssemblyChecker false - - - - <_jitToolsRidPlatformIndex>$(OutputRID.LastIndexOf('-')) - $(OutputRID.Substring(0, $(_jitToolsRidPlatformIndex))) - $(OutputRID.Substring($(_jitToolsRidPlatformIndex)).TrimStart('-')) - - - linux - - - x64 - arm64 - $(JITToolsRidWithoutPlatform)-$(JITToolsRidPlatform) - - $(runtimelinuxarm64MicrosoftNETCoreRuntimeJITToolsVersion) - $(runtimelinuxx64MicrosoftNETCoreRuntimeJITToolsVersion) - $(runtimelinuxmuslarm64MicrosoftNETCoreRuntimeJITToolsVersion) - $(runtimelinuxmuslx64MicrosoftNETCoreRuntimeJITToolsVersion) - $(runtimewinarm64MicrosoftNETCoreRuntimeJITToolsVersion) - $(runtimewinx64MicrosoftNETCoreRuntimeJITToolsVersion) - $(runtimeosxarm64MicrosoftNETCoreRuntimeJITToolsVersion) - $(runtimeosxx64MicrosoftNETCoreRuntimeJITToolsVersion) - - - - - - [$(JITToolsVersion)] - - - - - - - - - - From e9abeb4eaad0cd9aba3941fb33b3450743b51340 Mon Sep 17 00:00:00 2001 From: Will Smith Date: Tue, 17 Oct 2023 12:08:07 -0700 Subject: [PATCH 24/41] Update Program.cs --- src/coreclr/tools/AssemblyChecker/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/tools/AssemblyChecker/Program.cs b/src/coreclr/tools/AssemblyChecker/Program.cs index a8bc45ff50b86..1ef1185a4d1c0 100644 --- a/src/coreclr/tools/AssemblyChecker/Program.cs +++ b/src/coreclr/tools/AssemblyChecker/Program.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // This is a simple console application that is designed to answer True or False -// questions about whether a give file is a managed assembly or not. +// 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. From 5f57ed6f3c93665616547e544a6f22dc855376df Mon Sep 17 00:00:00 2001 From: TIHan Date: Tue, 17 Oct 2023 14:50:26 -0700 Subject: [PATCH 25/41] Trying to fix calling python on helix. --- src/tests/Common/CLRTest.Jit.targets | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/tests/Common/CLRTest.Jit.targets b/src/tests/Common/CLRTest.Jit.targets index 894434ad1434a..6ba242a1a4ae6 100644 --- a/src/tests/Common/CLRTest.Jit.targets +++ b/src/tests/Common/CLRTest.Jit.targets @@ -65,7 +65,12 @@ then mkdir IL-RT if [ "$(IsMergedTestRunnerAssembly)" = "true" ] then - python $(AssemblyName)_ilasmroundtrip.py + python3 $(AssemblyName)_ilasmroundtrip.py + if [ $ERRORLEVEL -ne 0 ] + then + echo EXECUTION OF ILDASM - FAILED $ERRORLEVEL + exit 1 + fi fi cp $(InputAssemblyName) $(TargetAssemblyName) echo "$CORE_ROOT/ildasm" -raweh -unicode -out=$(DisassemblyName) $(TargetAssemblyName) @@ -153,6 +158,10 @@ IF NOT DEFINED DoLink ( mkdir IL-RT IF "$(IsMergedTestRunnerAssembly)"=="true" ( python $(AssemblyName)_ilasmroundtrip.py + IF NOT "!ERRORLEVEL!"=="0" ( + ECHO EXECUTION OF ILDASM - FAILED !ERRORLEVEL! + Exit /b 1 + ) ) copy $(InputAssemblyName) $(TargetAssemblyName) ECHO %CORE_ROOT%\ildasm.exe /raweh /unicode /out=$(DisassemblyName) $(TargetAssemblyName) From ca91893278ea0161e13235310fd277640c7f72cf Mon Sep 17 00:00:00 2001 From: TIHan Date: Tue, 17 Oct 2023 15:53:30 -0700 Subject: [PATCH 26/41] Remove old roundtrip script calls. Added --is-exe option for AssemblyChecker. --- src/coreclr/tools/AssemblyChecker/Program.cs | 36 ++++++- src/tests/Common/CLRTest.Jit.targets | 108 ++++--------------- 2 files changed, 52 insertions(+), 92 deletions(-) diff --git a/src/coreclr/tools/AssemblyChecker/Program.cs b/src/coreclr/tools/AssemblyChecker/Program.cs index 1ef1185a4d1c0..761ebb6aeee56 100644 --- a/src/coreclr/tools/AssemblyChecker/Program.cs +++ b/src/coreclr/tools/AssemblyChecker/Program.cs @@ -81,6 +81,21 @@ static bool IsDebug(string path) return attrs.Any(x => HasDebuggableAttribute(reader, reader.GetCustomAttribute(x).Constructor)); } + 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) @@ -99,12 +114,23 @@ static int Main(string[] args) if (args.Length == 2) { - if (args[0] == "--is-debug") + switch (args[0]) { - if (IsDebug(args[1])) - return 0; - else - return 1; + case "--is-debug": + { + if (IsDebug(args[1])) + return 0; + else + return 1; + } + + case "--is-exe": + { + if (IsExe(args[1])) + return 0; + else + return 1; + } } else { diff --git a/src/tests/Common/CLRTest.Jit.targets b/src/tests/Common/CLRTest.Jit.targets index 6ba242a1a4ae6..39fdf6d9b3a6e 100644 --- a/src/tests/Common/CLRTest.Jit.targets +++ b/src/tests/Common/CLRTest.Jit.targets @@ -57,61 +57,14 @@ export RunningIlasmRoundTrip= @@ -387,7 +307,7 @@ set DOTNET_JitPath=%CORE_ROOT%\superpmi-shim-collector.dll *********************************************************************************************** --> - + $(AssemblyName).dll IL-RT/$(AssemblyName).il @@ -421,6 +341,16 @@ def is_managed_debug_assembly(file): proc.kill() return False +def is_managed_exe_assembly(file): + proc = subprocess.Popen(f'{os.environ["CORE_ROOT"]}/corerun {os.environ["CORE_ROOT"]}/AssemblyChecker/AssemblyChecker.dll --is-exe {file}') + + try: + proc.communicate() + return proc.returncode == 0 + except: + proc.kill() + return False + print("") print("ILASM RoundTrips") @@ -434,8 +364,12 @@ for inputAssemblyName in glob.glob("*.dll"): print("ILASM RoundTrip for " + inputAssemblyName) ilasmSwitches = "" + + if not is_managed_exe_assembly(inputAssemblyName): + ilasmSwitches = ilasmSwitches + " /DLL" + if is_managed_debug_assembly(inputAssemblyName): - ilasmSwitches = "-DEBUG" + ilasmSwitches = ilasmSwitches + " -DEBUG" disassemblyName = os.path.join("IL-RT", os.path.splitext(os.path.basename(inputAssemblyName))[0] + ".il") targetAssemblyName = os.path.join("IL-RT", os.path.basename(inputAssemblyName)) From ba6fc6ff9b2b18e62058fcc92c2f6fe9a4af9ac2 Mon Sep 17 00:00:00 2001 From: TIHan Date: Tue, 17 Oct 2023 15:54:47 -0700 Subject: [PATCH 27/41] Tweak option: --- src/tests/Common/CLRTest.Jit.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/Common/CLRTest.Jit.targets b/src/tests/Common/CLRTest.Jit.targets index 39fdf6d9b3a6e..e7b69d823b3b8 100644 --- a/src/tests/Common/CLRTest.Jit.targets +++ b/src/tests/Common/CLRTest.Jit.targets @@ -384,7 +384,7 @@ for inputAssemblyName in glob.glob("*.dll"): proc.kill() sys.exit(1) - proc = subprocess.Popen(f'{os.environ["CORE_ROOT"]}/ilasm /DLL /output={inputAssemblyName} {ilasmSwitches} {disassemblyName}') + proc = subprocess.Popen(f'{os.environ["CORE_ROOT"]}/ilasm /output={inputAssemblyName} {ilasmSwitches} {disassemblyName}') try: proc.communicate() From d5643960e2301ade6f564e699401dc173d0c6d54 Mon Sep 17 00:00:00 2001 From: TIHan Date: Tue, 17 Oct 2023 16:15:02 -0700 Subject: [PATCH 28/41] Remove check --- src/tests/Common/CLRTest.Jit.targets | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/tests/Common/CLRTest.Jit.targets b/src/tests/Common/CLRTest.Jit.targets index e7b69d823b3b8..e9bbb8e496f65 100644 --- a/src/tests/Common/CLRTest.Jit.targets +++ b/src/tests/Common/CLRTest.Jit.targets @@ -358,9 +358,7 @@ if not os.path.exists("IL-RT"): os.mkdir("IL-RT") for inputAssemblyName in glob.glob("*.dll"): - # Roundtrips library assemblies. Executable assemblies are done in the bash/batch scripts. - # We filter out the executable assembly that this script gets generated from. - if (not inputAssemblyName.endswith("$(AssemblyName).dll")) and is_managed_assembly(inputAssemblyName): + if is_managed_assembly(inputAssemblyName): print("ILASM RoundTrip for " + inputAssemblyName) ilasmSwitches = "" From c9d1e49bf79fbc03197cacb9a328719f07a2b8b1 Mon Sep 17 00:00:00 2001 From: TIHan Date: Tue, 17 Oct 2023 16:17:58 -0700 Subject: [PATCH 29/41] Remove imports --- src/tests/Common/CLRTest.Jit.targets | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/tests/Common/CLRTest.Jit.targets b/src/tests/Common/CLRTest.Jit.targets index e9bbb8e496f65..71ae8a6393113 100644 --- a/src/tests/Common/CLRTest.Jit.targets +++ b/src/tests/Common/CLRTest.Jit.targets @@ -318,8 +318,6 @@ import shutil import subprocess import sys import glob -import struct -import platform def is_managed_assembly(file): proc = subprocess.Popen(f'{os.environ["CORE_ROOT"]}/corerun {os.environ["CORE_ROOT"]}/AssemblyChecker/AssemblyChecker.dll {file}') From 18914d878d69ac80ad0fea038fe2fda68bf3d760 Mon Sep 17 00:00:00 2001 From: TIHan Date: Tue, 17 Oct 2023 17:21:51 -0700 Subject: [PATCH 30/41] Fix build --- src/coreclr/tools/AssemblyChecker/Program.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/coreclr/tools/AssemblyChecker/Program.cs b/src/coreclr/tools/AssemblyChecker/Program.cs index 761ebb6aeee56..8cb2f6a1b9c56 100644 --- a/src/coreclr/tools/AssemblyChecker/Program.cs +++ b/src/coreclr/tools/AssemblyChecker/Program.cs @@ -131,11 +131,12 @@ static int Main(string[] args) else return 1; } - } - else - { - Console.Error.WriteLine("Invalid option."); - return 2; + + default: + { + Console.Error.WriteLine("Invalid option."); + return 2; + } } } From 1a6476a113953e86cd0f66e38218909bebe79fbe Mon Sep 17 00:00:00 2001 From: TIHan Date: Wed, 18 Oct 2023 00:01:45 -0700 Subject: [PATCH 31/41] Fix syntax errors. Fixed Popen arguments --- src/tests/Common/CLRTest.Jit.targets | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/tests/Common/CLRTest.Jit.targets b/src/tests/Common/CLRTest.Jit.targets index 71ae8a6393113..b8f9907282c61 100644 --- a/src/tests/Common/CLRTest.Jit.targets +++ b/src/tests/Common/CLRTest.Jit.targets @@ -112,6 +112,7 @@ IF NOT DEFINED DoLink ( ECHO ILASM ROUND-TRIP - FAILED !ERRORLEVEL! Exit /b 1 ) + ) ) ]]> @@ -320,7 +321,7 @@ import sys import glob def is_managed_assembly(file): - proc = subprocess.Popen(f'{os.environ["CORE_ROOT"]}/corerun {os.environ["CORE_ROOT"]}/AssemblyChecker/AssemblyChecker.dll {file}') + proc = subprocess.Popen([f'{os.environ["CORE_ROOT"]}/corerun', f'{os.environ["CORE_ROOT"]}/AssemblyChecker/AssemblyChecker.dll', f'{file}']) try: proc.communicate() @@ -330,7 +331,7 @@ def is_managed_assembly(file): return False def is_managed_debug_assembly(file): - proc = subprocess.Popen(f'{os.environ["CORE_ROOT"]}/corerun {os.environ["CORE_ROOT"]}/AssemblyChecker/AssemblyChecker.dll --is-debug {file}') + proc = subprocess.Popen([f'{os.environ["CORE_ROOT"]}/corerun', f'{os.environ["CORE_ROOT"]}/AssemblyChecker/AssemblyChecker.dll', "--is-debug", f'{file}']) try: proc.communicate() @@ -340,7 +341,7 @@ def is_managed_debug_assembly(file): return False def is_managed_exe_assembly(file): - proc = subprocess.Popen(f'{os.environ["CORE_ROOT"]}/corerun {os.environ["CORE_ROOT"]}/AssemblyChecker/AssemblyChecker.dll --is-exe {file}') + proc = subprocess.Popen([f'{os.environ["CORE_ROOT"]}/corerun', f'{os.environ["CORE_ROOT"]}/AssemblyChecker/AssemblyChecker.dll', "--is-exe", f'{file}']) try: proc.communicate() From 4e97e0564d2111adc3df28dca8d0a43afe4a18c0 Mon Sep 17 00:00:00 2001 From: TIHan Date: Wed, 18 Oct 2023 00:30:52 -0700 Subject: [PATCH 32/41] Fixed Popen arguments --- src/tests/Common/CLRTest.Jit.targets | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/tests/Common/CLRTest.Jit.targets b/src/tests/Common/CLRTest.Jit.targets index b8f9907282c61..32f2fdd05d46f 100644 --- a/src/tests/Common/CLRTest.Jit.targets +++ b/src/tests/Common/CLRTest.Jit.targets @@ -321,7 +321,7 @@ import sys import glob def is_managed_assembly(file): - proc = subprocess.Popen([f'{os.environ["CORE_ROOT"]}/corerun', f'{os.environ["CORE_ROOT"]}/AssemblyChecker/AssemblyChecker.dll', f'{file}']) + proc = subprocess.Popen([f'{os.environ["CORE_ROOT"]}/corerun', f'{os.environ["CORE_ROOT"]}/AssemblyChecker/AssemblyChecker.dll', file]) try: proc.communicate() @@ -331,7 +331,7 @@ def is_managed_assembly(file): return False def is_managed_debug_assembly(file): - proc = subprocess.Popen([f'{os.environ["CORE_ROOT"]}/corerun', f'{os.environ["CORE_ROOT"]}/AssemblyChecker/AssemblyChecker.dll', "--is-debug", f'{file}']) + proc = subprocess.Popen([f'{os.environ["CORE_ROOT"]}/corerun', f'{os.environ["CORE_ROOT"]}/AssemblyChecker/AssemblyChecker.dll', "--is-debug", file]) try: proc.communicate() @@ -341,7 +341,7 @@ def is_managed_debug_assembly(file): return False def is_managed_exe_assembly(file): - proc = subprocess.Popen([f'{os.environ["CORE_ROOT"]}/corerun', f'{os.environ["CORE_ROOT"]}/AssemblyChecker/AssemblyChecker.dll', "--is-exe", f'{file}']) + proc = subprocess.Popen([f'{os.environ["CORE_ROOT"]}/corerun', f'{os.environ["CORE_ROOT"]}/AssemblyChecker/AssemblyChecker.dll', "--is-exe", file]) try: proc.communicate() @@ -363,7 +363,7 @@ for inputAssemblyName in glob.glob("*.dll"): ilasmSwitches = "" if not is_managed_exe_assembly(inputAssemblyName): - ilasmSwitches = ilasmSwitches + " /DLL" + ilasmSwitches = ilasmSwitches + " -DLL" if is_managed_debug_assembly(inputAssemblyName): ilasmSwitches = ilasmSwitches + " -DEBUG" @@ -373,7 +373,7 @@ for inputAssemblyName in glob.glob("*.dll"): shutil.copyfile(inputAssemblyName, targetAssemblyName) - proc = subprocess.Popen(f'{os.environ["CORE_ROOT"]}/ildasm /raweh /unicode /out={disassemblyName} {targetAssemblyName}') + proc = subprocess.Popen(f'{os.environ["CORE_ROOT"]}/ildasm -raweh -unicode -out={disassemblyName} {targetAssemblyName}', shell=True) try: proc.communicate() @@ -381,7 +381,7 @@ for inputAssemblyName in glob.glob("*.dll"): proc.kill() sys.exit(1) - proc = subprocess.Popen(f'{os.environ["CORE_ROOT"]}/ilasm /output={inputAssemblyName} {ilasmSwitches} {disassemblyName}') + proc = subprocess.Popen(f'{os.environ["CORE_ROOT"]}/ilasm -output={inputAssemblyName} {ilasmSwitches} {disassemblyName}', shell=True) try: proc.communicate() From b2c85b975041a6fdafd37219dd9613fc884e77c9 Mon Sep 17 00:00:00 2001 From: TIHan Date: Wed, 18 Oct 2023 12:46:21 -0700 Subject: [PATCH 33/41] Fixing debug check --- src/coreclr/tools/AssemblyChecker/Program.cs | 51 ++++++-------------- src/tests/Common/CLRTest.Jit.targets | 8 ++- 2 files changed, 20 insertions(+), 39 deletions(-) diff --git a/src/coreclr/tools/AssemblyChecker/Program.cs b/src/coreclr/tools/AssemblyChecker/Program.cs index 8cb2f6a1b9c56..cf7914325da92 100644 --- a/src/coreclr/tools/AssemblyChecker/Program.cs +++ b/src/coreclr/tools/AssemblyChecker/Program.cs @@ -9,6 +9,7 @@ using System.Text; using System.Diagnostics; +using System.Reflection; using System.Reflection.Metadata; using System.Reflection.PortableExecutable; @@ -33,52 +34,28 @@ static bool IsAssembly(string path) return reader.IsAssembly; } - static bool HasDebuggableAttribute(MetadataReader reader, EntityHandle entity) + static bool IsDebug(string path) { - if (entity.IsNil) - return false; + var asm = Assembly.LoadFrom(path); + object[] attribs = asm.GetCustomAttributes(typeof(DebuggableAttribute), false); - switch (entity.Kind) + if (attribs.Length > 0) { - case HandleKind.MemberReference: + return + attribs.Any(x => { - var memRef = reader.GetMemberReference((MemberReferenceHandle)entity); - switch (memRef.Parent.Kind) + DebuggableAttribute? debuggableAttribute = attribs[0] as DebuggableAttribute; + if (debuggableAttribute != null) { - case HandleKind.TypeReference: - { - var tyRef = reader.GetTypeReference((TypeReferenceHandle)memRef.Parent); - return reader.GetString(tyRef.Name) == "DebuggableAttribute"; - } - - default: - return false; + return debuggableAttribute.IsJITOptimizerDisabled; } - } - - default: - return false; + return false; + }); } - - } - - static bool IsDebug(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) + else { - return false; // File does not have CLI metadata. + return false; } - - // Check that file has an assembly manifest. - MetadataReader reader = peReader.GetMetadataReader(); - - var attrs = reader.GetAssemblyDefinition().GetCustomAttributes(); - return attrs.Any(x => HasDebuggableAttribute(reader, reader.GetCustomAttribute(x).Constructor)); } static bool IsExe(string path) diff --git a/src/tests/Common/CLRTest.Jit.targets b/src/tests/Common/CLRTest.Jit.targets index 32f2fdd05d46f..e827160b34df8 100644 --- a/src/tests/Common/CLRTest.Jit.targets +++ b/src/tests/Common/CLRTest.Jit.targets @@ -373,7 +373,9 @@ for inputAssemblyName in glob.glob("*.dll"): shutil.copyfile(inputAssemblyName, targetAssemblyName) - proc = subprocess.Popen(f'{os.environ["CORE_ROOT"]}/ildasm -raweh -unicode -out={disassemblyName} {targetAssemblyName}', shell=True) + ildasm_args = f'{os.environ["CORE_ROOT"]}/ildasm -raweh -unicode -out={disassemblyName} {targetAssemblyName}' + print(ildasm_args) + proc = subprocess.Popen(ildasm_args, shell=True) try: proc.communicate() @@ -381,7 +383,9 @@ for inputAssemblyName in glob.glob("*.dll"): proc.kill() sys.exit(1) - proc = subprocess.Popen(f'{os.environ["CORE_ROOT"]}/ilasm -output={inputAssemblyName} {ilasmSwitches} {disassemblyName}', shell=True) + ilasm_args = f'{os.environ["CORE_ROOT"]}/ilasm -output={inputAssemblyName} {ilasmSwitches} {disassemblyName}' + print(ilasm_args) + proc = subprocess.Popen(ilasm_args, shell=True) try: proc.communicate() From e25f1d4d56c8aabea86a839154c401c8be1e2c56 Mon Sep 17 00:00:00 2001 From: TIHan Date: Wed, 18 Oct 2023 16:53:20 -0700 Subject: [PATCH 34/41] Fixing tests --- src/tests/Common/CLRTest.Jit.targets | 22 ++++++++++++++----- .../Methodical/fp/exgen/10w5d_cs_do.csproj | 1 + .../CodeQuality/Bytemark/Bytemark.csproj | 1 + .../CodeQuality/Roslyn/CscBench.csproj | 1 + src/tests/ilverify/ILVerificationTests.csproj | 1 + 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/tests/Common/CLRTest.Jit.targets b/src/tests/Common/CLRTest.Jit.targets index e827160b34df8..51429c6239dbf 100644 --- a/src/tests/Common/CLRTest.Jit.targets +++ b/src/tests/Common/CLRTest.Jit.targets @@ -55,7 +55,7 @@ export RunningIlasmRoundTrip= ]]> - - - - - + $(AssemblyName).dll IL-RT/$(AssemblyName).il @@ -356,8 +356,18 @@ print("ILASM RoundTrips") if not os.path.exists("IL-RT"): os.mkdir("IL-RT") +assembliesToIgnore = [ + "Loader/binding/tracing/BinderTracingTest.ResolutionFlow/AssemblyToLoad.dll" +] + +def can_ignore_assembly(absPath): + for path in assembliesToIgnore: + if absPath.endswith(path): + return True + return False + for inputAssemblyName in glob.glob("*.dll"): - if is_managed_assembly(inputAssemblyName): + if not can_ignore_assembly(os.path.abspath(inputAssemblyName).replace("\\", "/")) and is_managed_assembly(inputAssemblyName): print("ILASM RoundTrip for " + inputAssemblyName) ilasmSwitches = "" diff --git a/src/tests/JIT/Methodical/fp/exgen/10w5d_cs_do.csproj b/src/tests/JIT/Methodical/fp/exgen/10w5d_cs_do.csproj index 9eff379e0d455..d1e37c52b6423 100644 --- a/src/tests/JIT/Methodical/fp/exgen/10w5d_cs_do.csproj +++ b/src/tests/JIT/Methodical/fp/exgen/10w5d_cs_do.csproj @@ -3,6 +3,7 @@ true + true Full diff --git a/src/tests/JIT/Performance/CodeQuality/Bytemark/Bytemark.csproj b/src/tests/JIT/Performance/CodeQuality/Bytemark/Bytemark.csproj index 03274a86e59cc..de85a9ce57835 100644 --- a/src/tests/JIT/Performance/CodeQuality/Bytemark/Bytemark.csproj +++ b/src/tests/JIT/Performance/CodeQuality/Bytemark/Bytemark.csproj @@ -3,6 +3,7 @@ true true + true $(NoWarn);xUnit1013 true diff --git a/src/tests/JIT/Performance/CodeQuality/Roslyn/CscBench.csproj b/src/tests/JIT/Performance/CodeQuality/Roslyn/CscBench.csproj index 37d4ba53a4c2b..045dc9053d1af 100644 --- a/src/tests/JIT/Performance/CodeQuality/Roslyn/CscBench.csproj +++ b/src/tests/JIT/Performance/CodeQuality/Roslyn/CscBench.csproj @@ -6,6 +6,7 @@ $(NoWarn);xUnit1013 true true + true pdbonly diff --git a/src/tests/ilverify/ILVerificationTests.csproj b/src/tests/ilverify/ILVerificationTests.csproj index 3144da43d0c20..a58e416d42986 100644 --- a/src/tests/ilverify/ILVerificationTests.csproj +++ b/src/tests/ilverify/ILVerificationTests.csproj @@ -5,6 +5,7 @@ true true + true From 2ed31dafea408c703c99ca840f83d3d249558aef Mon Sep 17 00:00:00 2001 From: Will Smith Date: Thu, 19 Oct 2023 09:31:32 -0700 Subject: [PATCH 35/41] Update ILVerificationTests.csproj --- src/tests/ilverify/ILVerificationTests.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tests/ilverify/ILVerificationTests.csproj b/src/tests/ilverify/ILVerificationTests.csproj index a58e416d42986..f9f7e7521ffaf 100644 --- a/src/tests/ilverify/ILVerificationTests.csproj +++ b/src/tests/ilverify/ILVerificationTests.csproj @@ -6,6 +6,7 @@ true true true + true From f9c41e9a296a18d91b7a685824be23413e21614b Mon Sep 17 00:00:00 2001 From: TIHan Date: Thu, 19 Oct 2023 09:34:28 -0700 Subject: [PATCH 36/41] Fixing tests --- src/tests/Common/CLRTest.Jit.targets | 12 +----------- .../tracing/BinderTracingTest.ResolutionFlow.csproj | 2 ++ 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/tests/Common/CLRTest.Jit.targets b/src/tests/Common/CLRTest.Jit.targets index 51429c6239dbf..238491974d7d1 100644 --- a/src/tests/Common/CLRTest.Jit.targets +++ b/src/tests/Common/CLRTest.Jit.targets @@ -356,18 +356,8 @@ print("ILASM RoundTrips") if not os.path.exists("IL-RT"): os.mkdir("IL-RT") -assembliesToIgnore = [ - "Loader/binding/tracing/BinderTracingTest.ResolutionFlow/AssemblyToLoad.dll" -] - -def can_ignore_assembly(absPath): - for path in assembliesToIgnore: - if absPath.endswith(path): - return True - return False - for inputAssemblyName in glob.glob("*.dll"): - if not can_ignore_assembly(os.path.abspath(inputAssemblyName).replace("\\", "/")) and is_managed_assembly(inputAssemblyName): + if is_managed_assembly(inputAssemblyName): print("ILASM RoundTrip for " + inputAssemblyName) ilasmSwitches = "" diff --git a/src/tests/Loader/binding/tracing/BinderTracingTest.ResolutionFlow.csproj b/src/tests/Loader/binding/tracing/BinderTracingTest.ResolutionFlow.csproj index 0bb68d9cb843d..07f4907e396c9 100644 --- a/src/tests/Loader/binding/tracing/BinderTracingTest.ResolutionFlow.csproj +++ b/src/tests/Loader/binding/tracing/BinderTracingTest.ResolutionFlow.csproj @@ -4,6 +4,8 @@ true true + true + true From fe51ff1c165894e0dc911eb71eba59a65aefb7e0 Mon Sep 17 00:00:00 2001 From: TIHan Date: Mon, 23 Oct 2023 14:22:57 -0700 Subject: [PATCH 37/41] Feedback --- src/coreclr/tools/AssemblyChecker/Program.cs | 13 +++++++------ src/tests/Common/CLRTest.Jit.targets | 4 ++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/coreclr/tools/AssemblyChecker/Program.cs b/src/coreclr/tools/AssemblyChecker/Program.cs index cf7914325da92..601567477577f 100644 --- a/src/coreclr/tools/AssemblyChecker/Program.cs +++ b/src/coreclr/tools/AssemblyChecker/Program.cs @@ -1,12 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// 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. - using System.Text; using System.Diagnostics; using System.Reflection; @@ -15,6 +9,13 @@ namespace AssemblyChecker { + /// + /// 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. + /// public class Program { static bool IsAssembly(string path) diff --git a/src/tests/Common/CLRTest.Jit.targets b/src/tests/Common/CLRTest.Jit.targets index 238491974d7d1..d432cded005ce 100644 --- a/src/tests/Common/CLRTest.Jit.targets +++ b/src/tests/Common/CLRTest.Jit.targets @@ -57,6 +57,8 @@ export RunningIlasmRoundTrip= Date: Tue, 24 Oct 2023 12:53:19 -0700 Subject: [PATCH 38/41] Feedback --- src/tests/Common/CLRTest.Execute.Bash.targets | 4 --- .../Common/CLRTest.Execute.Batch.targets | 2 -- src/tests/Common/CLRTest.Jit.targets | 27 ------------------- 3 files changed, 33 deletions(-) diff --git a/src/tests/Common/CLRTest.Execute.Bash.targets b/src/tests/Common/CLRTest.Execute.Bash.targets index ea33ed79bad9b..81a50db81cacc 100644 --- a/src/tests/Common/CLRTest.Execute.Bash.targets +++ b/src/tests/Common/CLRTest.Execute.Bash.targets @@ -381,8 +381,6 @@ else LAUNCHER="$_DebuggerFullPath $_DebuggerArgsSeparator $(CLRTestRunFile)" fi -$(BashIlrtTestLaunchCmds) - if [ ! -z ${RunCrossGen2+x} ]%3B then TakeLock fi @@ -412,8 +410,6 @@ else LAUNCHER="$_DebuggerFullPath $_DebuggerArgsSeparator $(CLRTestRunFile)" fi -$(BashIlrtTestLaunchCmds) - if [ ! -z ${RunCrossGen2+x} ]%3B then TakeLock fi diff --git a/src/tests/Common/CLRTest.Execute.Batch.targets b/src/tests/Common/CLRTest.Execute.Batch.targets index 90ba71856b72e..f19c8987bbc6f 100644 --- a/src/tests/Common/CLRTest.Execute.Batch.targets +++ b/src/tests/Common/CLRTest.Execute.Batch.targets @@ -318,8 +318,6 @@ IF NOT "%CLRCustomTestLauncher%"=="" ( set LAUNCHER=%_DebuggerFullPath% $(CLRTestRunFile) ) -$(BatchIlrtTestLaunchCmds) - if defined RunCrossGen2 ( call :TakeLock ) diff --git a/src/tests/Common/CLRTest.Jit.targets b/src/tests/Common/CLRTest.Jit.targets index d432cded005ce..962616fbcdf0f 100644 --- a/src/tests/Common/CLRTest.Jit.targets +++ b/src/tests/Common/CLRTest.Jit.targets @@ -72,20 +72,6 @@ then fi ]]> - - @@ -120,19 +106,6 @@ IF NOT DEFINED DoLink ( ) ]]> - - From 7b4796af44eb6a1d7d1e8068d19b40f15a5f82d3 Mon Sep 17 00:00:00 2001 From: Will Smith Date: Fri, 27 Oct 2023 13:45:54 -0700 Subject: [PATCH 39/41] Update CLRTest.Jit.targets --- src/tests/Common/CLRTest.Jit.targets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/Common/CLRTest.Jit.targets b/src/tests/Common/CLRTest.Jit.targets index 962616fbcdf0f..476595df0c8be 100644 --- a/src/tests/Common/CLRTest.Jit.targets +++ b/src/tests/Common/CLRTest.Jit.targets @@ -55,7 +55,7 @@ export RunningIlasmRoundTrip= ]]> - - Date: Fri, 27 Oct 2023 13:55:57 -0700 Subject: [PATCH 40/41] Added help usage flag for AssemblyChecker --- src/coreclr/tools/AssemblyChecker/Program.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/coreclr/tools/AssemblyChecker/Program.cs b/src/coreclr/tools/AssemblyChecker/Program.cs index 601567477577f..f775684c4e83a 100644 --- a/src/coreclr/tools/AssemblyChecker/Program.cs +++ b/src/coreclr/tools/AssemblyChecker/Program.cs @@ -18,6 +18,13 @@ namespace AssemblyChecker /// public class Program { + private const string HelpText = @" +Usage: + : Check if the file-path is a managed assembly. + --is-debug : Check if the file-path is a managed assembly that is built with debuggability. + --is-exe : 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); @@ -82,6 +89,13 @@ static int Main(string[] args) return 2; } + // Help + if (args.Contains("-h")) + { + Console.WriteLine(HelpText); + return 0; + } + if (args.Length == 1) { if (IsAssembly(args[0])) From 4a2442eabfc6f5669e2734ccd4f76312f9619c8b Mon Sep 17 00:00:00 2001 From: TIHan Date: Sun, 29 Oct 2023 14:54:43 -0700 Subject: [PATCH 41/41] Feedback on assembly-checker --- src/coreclr/tools/AssemblyChecker/Program.cs | 48 ++++++-------------- 1 file changed, 13 insertions(+), 35 deletions(-) diff --git a/src/coreclr/tools/AssemblyChecker/Program.cs b/src/coreclr/tools/AssemblyChecker/Program.cs index f775684c4e83a..69f86e050beb2 100644 --- a/src/coreclr/tools/AssemblyChecker/Program.cs +++ b/src/coreclr/tools/AssemblyChecker/Program.cs @@ -44,26 +44,10 @@ static bool IsAssembly(string path) static bool IsDebug(string path) { - var asm = Assembly.LoadFrom(path); - object[] attribs = asm.GetCustomAttributes(typeof(DebuggableAttribute), false); - - if (attribs.Length > 0) - { - return - attribs.Any(x => - { - DebuggableAttribute? debuggableAttribute = attribs[0] as DebuggableAttribute; - if (debuggableAttribute != null) - { - return debuggableAttribute.IsJITOptimizerDisabled; - } - return false; - }); - } - else - { - return false; - } + return + Assembly.LoadFrom(path) + .GetCustomAttributes(typeof(DebuggableAttribute), false) + .OfType().Any(x => x.IsJITOptimizerDisabled); } static bool IsExe(string path) @@ -85,7 +69,8 @@ static int Main(string[] args) { if (args.Length == 0) { - Console.Error.WriteLine("Expected assembly file-path."); + Console.WriteLine(HelpText); + Console.Error.WriteLine("\nExpected assembly file-path."); return 2; } @@ -98,10 +83,7 @@ static int Main(string[] args) if (args.Length == 1) { - if (IsAssembly(args[0])) - return 0; - else - return 1; + return IsAssembly(args[0]) ? 0 : 1; } if (args.Length == 2) @@ -110,29 +92,25 @@ static int Main(string[] args) { case "--is-debug": { - if (IsDebug(args[1])) - return 0; - else - return 1; + return IsDebug(args[1]) ? 0 : 1; } case "--is-exe": { - if (IsExe(args[1])) - return 0; - else - return 1; + return IsExe(args[1]) ? 0 : 1; } default: { - Console.Error.WriteLine("Invalid option."); + Console.WriteLine(HelpText); + Console.Error.WriteLine("\nInvalid option."); return 2; } } } - Console.Error.WriteLine("Too many arguments."); + Console.WriteLine(HelpText); + Console.Error.WriteLine("\nToo many arguments."); return 2; } }