Skip to content

Commit

Permalink
Make wasmjit-diff.ps1 work with components
Browse files Browse the repository at this point in the history
Utilizing 'wasm-tools unbundle'.

Also change how the debug test exclusion works so
that it is buildable in Release (useful for diffs).
  • Loading branch information
SingleAccretion committed Jan 22, 2025
1 parent 3762f8e commit 4c716db
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/tests/Common/dirs.proj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<DisabledProjects Include="$(TestRoot)nativeaot\SmokeTests\SharedLibrary\SharedLibrary.csproj" />

<!-- Only automated on WASI with LLDB, which we don't have on Windows CI machines. -->
<DisabledProjects Include="$(TestRoot)nativeaot\SmokeTests\HelloWasm\WasmDebugging.csproj" Condition="'$(TargetOS)' == 'browser' or '$(OS)' == 'Windows_NT'" />
<DisabledProjects Include="$(TestRoot)nativeaot\SmokeTests\HelloWasm\WasmDebugging.csproj" Condition="'$(TargetOS)' == 'browser' or '$(OS)' == 'Windows_NT' or '$(Configuration)' != 'Debug'" />
<DisabledProjects Include="$(TestRoot)readytorun\**\*.csproj" Condition="'$(TestBuildMode)' == 'nativeaot'" />
</ItemGroup>

Expand Down
3 changes: 0 additions & 3 deletions src/tests/nativeaot/SmokeTests/HelloWasm/WasmDebugging.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
<InvariantGlobalization>true</InvariantGlobalization>
<RequiresProcessIsolation>true</RequiresProcessIsolation>
<ReferenceXUnitWrapperGenerator>false</ReferenceXUnitWrapperGenerator>

<!-- Only works without optimizations for now. -->
<CLRTestTargetUnsupported Condition="'$(Configuration)' != 'Debug'">true</CLRTestTargetUnsupported>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetsWasi)' == 'true'">
Expand Down
32 changes: 28 additions & 4 deletions src/tests/nativeaot/SmokeTests/HelloWasm/wasmjit-diff.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ if ($ShowHelp)
Write-Host " further inspected using tools like git-diff."
Write-Host ""
Write-Host " -Analyze depends on https://github.com/WebAssembly/wabt tools being available in PATH."
Write-Host " -Analyze for WASI depends on https://github.com/bytecodealliance/wasm-tools being available in PATH."
Write-Host " -Llvm depends on llvm-dis being available in PATH."
Write-Host ""
return
Expand Down Expand Up @@ -203,6 +204,29 @@ if ($Analyze -or $Summary)
}
else
{
function WasmObjDump($Options, $Path)
{
if ($OS -eq "wasi")
{
$UnbundlePath = "$([IO.Path]::GetDirectoryName($Path))/wasmjit-diff"
if (!(Test-Path $UnbundlePath))
{
mkdir $UnbundlePath > $null | Write-Verbose
}
$CoreModulePath = "$UnbundlePath/unbundled-module0.wasm"
$ComponentTimeStamp = (Get-ChildItem $Path).LastAccessTime
$CoreModuleTimeStamp = (Get-ChildItem $CoreModulePath -ErrorAction Ignore).LastAccessTime
if ($ComponentTimeStamp -gt $CoreModuleTimeStamp)
{
# Component newer than our cached core module, update the latter.
Write-Host "Unbundling $Path as $CoreModulePath"
wasm-tools component unbundle $Path --module-dir $UnbundlePath > $null
}
$Path = $CoreModulePath
}
return wasm-objdump @Options $Path
}

$WasmSummaryLineRegex = [Regex]::New(" - func\[(\d+)\] size=(\d+) <(.*)>", "Compiled")
function ParseWasmSummary($RawSummary, $SummaryName)
{
Expand Down Expand Up @@ -243,8 +267,8 @@ if ($Analyze -or $Summary)
return $SummaryList, $TotalCodeSize
}

$BaseSummaryRaw = wasm-objdump -x -j Code $TestProjectBaseWasmOutput
$DiffSummaryRaw = wasm-objdump -x -j Code $TestProjectWasmOutput
$BaseSummaryRaw = WasmObjDump @("-x", "-j", "Code") $TestProjectBaseWasmOutput
$DiffSummaryRaw = WasmObjDump @("-x", "-j", "Code") $TestProjectWasmOutput

$BaseSummary, $TotalBaseCodeSize = ParseWasmSummary $BaseSummaryRaw "base"
$DiffSummary, $TotalDiffCodeSize = ParseWasmSummary $DiffSummaryRaw "diff"
Expand Down Expand Up @@ -357,9 +381,9 @@ if ($Analyze -or $Summary)
else
{
Write-Host "Collecting full disassembly for the base..."
$BaseWat = wasm-objdump -d $TestProjectBaseWasmOutput
$BaseWat = WasmObjDump @("-d") $TestProjectBaseWasmOutput
Write-Host "Collecting full disassembly for the diff..."
$DiffWat = wasm-objdump -d $TestProjectWasmOutput
$DiffWat = WasmObjDump @("-d") $TestProjectWasmOutput

function CreateWatIndex($Wat)
{
Expand Down

0 comments on commit 4c716db

Please sign in to comment.