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

Enable IlasmRoundTrip tests for merged tests #93368

Merged
merged 42 commits into from
Oct 30, 2023
Merged
Changes from 17 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
8dd8951
Initial work
TIHan Oct 11, 2023
d348160
Tweak
TIHan Oct 11, 2023
41394cb
Tweak
TIHan Oct 11, 2023
d5afb0e
Do not generate _ilasmroundtrip.py for tests that have a generated ru…
TIHan Oct 11, 2023
c59ea7d
Reduce imports
TIHan Oct 11, 2023
a3a41cf
Force fail to see where CI fails
TIHan Oct 12, 2023
20adfcd
Revert forcing failure. Run roundtrip on build.
TIHan Oct 12, 2023
b91c82d
Trying to fix script
TIHan Oct 12, 2023
fa91e26
Backslash tweak
TIHan Oct 12, 2023
a825fe8
Do not roundtrip the same assembly
TIHan Oct 12, 2023
ede1994
Fixing
TIHan Oct 12, 2023
828c4b0
Remove import glob
TIHan Oct 12, 2023
844eb49
Added is_managed_assembly
TIHan Oct 12, 2023
265d870
remove print
TIHan Oct 12, 2023
cd497ac
Fixed paths
TIHan Oct 12, 2023
969369b
Support bash. Ignore certain tests for arm. Fix poison test.
TIHan Oct 13, 2023
c1e0b1f
Update CLRTest.Jit.targets
TIHan Oct 13, 2023
f654a59
Feedback. Added AssemblyChecker.
TIHan Oct 16, 2023
54d65a8
Merge branch 'ilasm-roundtrip-fix' of https://github.com/TIHan/runtim…
TIHan Oct 16, 2023
b06879a
Fix paths
TIHan Oct 17, 2023
9f8d9e8
Update src/tests/Common/Directory.Build.targets
TIHan Oct 17, 2023
9b7bf31
Feedback
TIHan Oct 17, 2023
0b14d98
Feedback
TIHan Oct 17, 2023
7aca653
Update AssemblyChecker.csproj
TIHan Oct 17, 2023
e9abeb4
Update Program.cs
TIHan Oct 17, 2023
5f57ed6
Trying to fix calling python on helix.
TIHan Oct 17, 2023
ca91893
Remove old roundtrip script calls. Added --is-exe option for Assembly…
TIHan Oct 17, 2023
ba6fc6f
Tweak option:
TIHan Oct 17, 2023
d564396
Remove check
TIHan Oct 17, 2023
c9d1e49
Remove imports
TIHan Oct 17, 2023
18914d8
Fix build
TIHan Oct 18, 2023
1a6476a
Fix syntax errors. Fixed Popen arguments
TIHan Oct 18, 2023
4e97e05
Fixed Popen arguments
TIHan Oct 18, 2023
b2c85b9
Fixing debug check
TIHan Oct 18, 2023
e25f1d4
Fixing tests
TIHan Oct 18, 2023
2ed31da
Update ILVerificationTests.csproj
TIHan Oct 19, 2023
f9c41e9
Fixing tests
TIHan Oct 19, 2023
fe51ff1
Feedback
TIHan Oct 23, 2023
703e89b
Feedback
TIHan Oct 24, 2023
7b4796a
Update CLRTest.Jit.targets
TIHan Oct 27, 2023
dcff071
Added help usage flag for AssemblyChecker
TIHan Oct 27, 2023
4a2442e
Feedback on assembly-checker
TIHan Oct 29, 2023
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
140 changes: 140 additions & 0 deletions src/tests/Common/CLRTest.Jit.targets
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export RunningIlasmRoundTrip=
if [ -z "$DoLink" -a ! -z "$RunningIlasmRoundTrip" ];
then
mkdir IL-RT
if [ "$(IsMergedTestRunnerAssembly)" = "true" ]
then
python $(AssemblyName)_ilasmroundtrip.py
fi
cp $(InputAssemblyName) $(TargetAssemblyName)
echo "$CORE_ROOT/ildasm" -raweh -unicode -out=$(DisassemblyName) $(TargetAssemblyName)
"$CORE_ROOT/ildasm" -raweh -unicode -out=$(DisassemblyName) $(TargetAssemblyName)
Expand Down Expand Up @@ -147,6 +151,9 @@ REM Todo: Ilasm round-trip on linked binaries.
IF NOT DEFINED DoLink (
IF DEFINED RunningIlasmRoundTrip (
mkdir IL-RT
IF "$(IsMergedTestRunnerAssembly)"=="true" (
python $(AssemblyName)_ilasmroundtrip.py
)
copy $(InputAssemblyName) $(TargetAssemblyName)
ECHO %CORE_ROOT%\ildasm.exe /raweh /unicode /out=$(DisassemblyName) $(TargetAssemblyName)
%CORE_ROOT%\ildasm.exe /raweh /unicode /out=$(DisassemblyName) $(TargetAssemblyName)
Expand Down Expand Up @@ -365,6 +372,139 @@ set DOTNET_JitPath=%CORE_ROOT%\superpmi-shim-collector.dll
</PropertyGroup>
</Target>

<!--
***********************************************************************************************
IlasmRoundTrip for merged tests
***********************************************************************************************
-->

<Target Name="IlasmRoundTripCommand" AfterTargets="AfterBuild" Condition="'$(IsMergedTestRunnerAssembly)' == 'true'">
<PropertyGroup>
<InputAssemblyName>$(AssemblyName).dll</InputAssemblyName>
<DisassemblyName>IL-RT/$(AssemblyName).il</DisassemblyName>
<TargetAssemblyName>IL-RT/$(AssemblyName).dll</TargetAssemblyName>
<_IlasmRoundTripScriptText><![CDATA[
import os
import shutil
import subprocess
import sys
import glob
import struct
import platform

def is_managed_assembly(file):
TIHan marked this conversation as resolved.
Show resolved Hide resolved
file_size = os.path.getsize(file)

if file_size < 64:
return False

with open(file, "rb") as f:
f.seek(0x3c)

# PE Header starts @ 0x3C (60). Its a 4 byte header.
peHeaderPointer = struct.unpack('I', f.read(4))[0]
TIHan marked this conversation as resolved.
Show resolved Hide resolved
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

print("")
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"
]
TIHan marked this conversation as resolved.
Show resolved Hide resolved
else:
assembliesToIgnore = []

for inputAssemblyName in glob.glob("*.dll"):
if (not inputAssemblyName.endswith("$(AssemblyName).dll")) and is_managed_assembly(inputAssemblyName):
TIHan marked this conversation as resolved.
Show resolved Hide resolved
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"):
ilasmSwitches = "-DEBUG"
TIHan marked this conversation as resolved.
Show resolved Hide resolved

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))

shutil.copyfile(inputAssemblyName, targetAssemblyName)

proc = subprocess.Popen(os.environ["CORE_ROOT"] + "/ildasm /raweh /unicode /out=" + disassemblyName + " " + targetAssemblyName)
TIHan marked this conversation as resolved.
Show resolved Hide resolved

try:
proc.communicate()
except:
proc.kill()
sys.exit(1)

proc = subprocess.Popen(os.environ["CORE_ROOT"] + "/ilasm /DLL /output=" + inputAssemblyName + " " + ilasmSwitches + " " + disassemblyName)

try:
proc.communicate()
except:
proc.kill()
sys.exit(1)

print("")

print("")

]]></_IlasmRoundTripScriptText>
</PropertyGroup>
<WriteLinesToFile
File="$(OutputPath)$(AssemblyName)_ilasmroundtrip.py"
Lines="$(_IlasmRoundTripScriptText)"
Overwrite="true" />
</Target>

<!--
***********************************************************************************************
GCStress settings
Expand Down
Loading