# Compile & run the kernel/upper-layer/format capability audit probes against a
#
# C-7b (task-80): probes now cover PDF3D import (U3D/PRC), XT/SAT/JT curve-body
# roundtrips, B-1 heal_with_rules, B-2 push_pull_draft/analytic offset, B-3
# fuse_all 1000 parts, B-4 patch continuity, B-6 feature-edit conflict rejection,
# A-5b boss feature-edit volume, A-10 .vde V1/V6, A-11 HLR 2D projection.
# built VDE tree.
# Usage: powershell -ExecutionPolicy Bypass -File tools/kernel_audit/run_audit.ps1
# [-BuildDir build] [-OutDir audit_out] [-NewApi] [-IncludeOverride
]
# -NewApi enable probes that need newer-than-frozen APIs
# (write_3mf_ex compression diagnostics, save_las, PDM catalog)
# -IncludeOverride prepend an ABI-matched header tree (e.g. a frozen tree's
# include/ copy) when the built libs predate the working tree.
param(
[string]$BuildDir = "build",
[string]$OutDir = "",
[switch]$NewApi,
[string]$IncludeOverride = ""
)
$ErrorActionPreference = "Continue"
$repoRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot) # /tools/kernel_audit ->
$auditDir = $PSScriptRoot
if (-not [System.IO.Path]::IsPathRooted($BuildDir)) { $BuildDir = Join-Path $repoRoot $BuildDir }
if ([string]::IsNullOrEmpty($OutDir)) { $OutDir = Join-Path $auditDir "out" }
New-Item -ItemType Directory -Force -Path $OutDir | Out-Null
$gppCmd = Get-Command g++ -ErrorAction SilentlyContinue
if (-not $gppCmd) { throw "g++ not found in PATH; install MinGW-w64 (WinLibs) or add it to PATH." }
$gpp = $gppCmd.Source
$libNames = @(
'libvde_compute.a','libvde_param.a','libvde_expression.a','libvde_event.a','libvde_drafting.a',
'libvde_infra.a','libvde_mechanism.a','libvde_pdm.a','libvde_license.a','libvde_ui.a',
'libvde_cam.a','libvde_render.a','libvde_sketch.a','libvde_capi.a','libvde_io.a','libvde_brep.a','libvde_boolean.a',
'libvde_sdf.a','libvde_mesh.a','libvde_curves.a','libvde_collision.a','libvde_spatial.a',
'libvde_core.a','libvde_foundation.a','libvde_platform.a')
$libs = @()
foreach ($n in $libNames) {
# Prefer the newest .a: a full frozen build dir may contain stale libs from an
# older layout (e.g. build/src/render vs build/src/vde_render both provide
# libvde_render.a; the former is an outdated copy without new symbols).
$p = Get-ChildItem -Path (Join-Path $BuildDir "src") -Recurse -Filter $n -File -ErrorAction SilentlyContinue |
Sort-Object LastWriteTime -Descending | Select-Object -First 1
if ($p) { $libs += $p.FullName }
}
if ($libs.Count -lt 5) { throw "VDE static libs not found under '$BuildDir/src'. Build the project first (cmake --build )." }
$common = @('-O1','-std=c++20','-DVDE_USE_OPENMP','-D_USE_MATH_DEFINES','-fopenmp')
if ($NewApi) { $common += '-DAUDIT_NEW_API' }
if ($IncludeOverride) { $common += "-I$IncludeOverride" }
$common += @("-I$(Join-Path $repoRoot 'include')","-I$(Join-Path $repoRoot 'src')",
"-I$(Join-Path $repoRoot 'src/sketch')",
"-I$(Join-Path $repoRoot 'json/include')",'-isystem', (Join-Path $repoRoot 'eigen3'))
$summary = @()
foreach ($probe in @('audit_brep','audit_curves','audit_mesh','audit_upper','audit_formats')) {
$src = Join-Path $auditDir "$probe.cpp"
$exe = Join-Path $OutDir "$probe.exe"
$log = Join-Path $OutDir "$probe.log"
Write-Host "=== $probe : compiling ==="
$args = $common + @($src, '-o', $exe, '-Wl,--start-group') + $libs + @('-Wl,--end-group','-lws2_32','-lgomp')
& $gpp @args
if ($LASTEXITCODE -ne 0) { Write-Host " compile FAILED (see g++ output above)"; $summary += "${probe}: COMPILE-FAILED"; continue }
Write-Host "=== $probe : running ==="
$out = & $exe 2>&1
$code = $LASTEXITCODE
$out | Set-Content -Path $log -Encoding UTF8
$pass = ($out | Select-String -Pattern '^\[PASS\]' | Measure-Object).Count
$fail = ($out | Select-String -Pattern '^\[FAIL\]' | Measure-Object).Count
$unk = ($out | Select-String -Pattern '^\[UNKNOWN\]' | Measure-Object).Count
$crash = if ($code -ne 0) { " (exit=$code, possible crash)" } else { "" }
$summary += "${probe}: PASS=$pass FAIL=$fail UNKNOWN=$unk$crash -> $log"
}
Write-Host ""
Write-Host "===== audit summary ====="
$summary | ForEach-Object { Write-Host $_ }