CultMath: commit the Unity import and dispatch smoke, with its broken control
packages/cultmath/scripts/unity-smoke/ holds the good compute shader, the deliberately broken control, the EditMode test (FindKernel, dispatch, readback), and run-unity-smoke.ps1, which builds a scratch project outside the repo with a file: path to the package, takes the Unity path as a parameter, requires all three tests to pass, and deletes the project. The package README's Unity section names it as the pre-tag step. Not -nographics: GetComputeShaderMessageCount reports 0 for a broken shader until FindKernel or Dispatch compiles it. Ran once on Starfire with Unity 6000.3.24f1: 3 passed, control rejected. Builds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
ab0eacd1c6
commit
b88fdccb75
6 changed files with 170 additions and 0 deletions
|
|
@ -127,6 +127,12 @@ The repository root is not a Unity package. Build the tracked package with
|
|||
assembly and rejects stale binaries, missing metadata, unexpected assemblies,
|
||||
or leaked C# source.
|
||||
|
||||
Before tagging `cultmath-unity-v*`, run the import and dispatch smoke on a Windows machine with a GPU,
|
||||
alone: `packages/cultmath/scripts/unity-smoke/run-unity-smoke.ps1 -UnityExe <path to Unity.exe>`. It
|
||||
builds a scratch project outside the repository that references the package by a `file:` path,
|
||||
dispatches a compute shader that includes `CultMath.Interval.hlsl` and `CultMath.Affine.hlsl`, requires
|
||||
a deliberately broken control shader to be rejected, and deletes the project afterwards.
|
||||
|
||||
## Shader Tooling
|
||||
|
||||
CultMath keeps portable DXC outside git under `packages/cultmath/.tools/`:
|
||||
|
|
|
|||
11
packages/cultmath/scripts/unity-smoke/Broken.compute
Normal file
11
packages/cultmath/scripts/unity-smoke/Broken.compute
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#pragma kernel CSMain
|
||||
#include "Packages/org.gamecult.cultmath/Shaders/CultMath.hlsl"
|
||||
#include "Packages/org.gamecult.cultmath/Shaders/CultMath.Interval.hlsl"
|
||||
#include "Packages/org.gamecult.cultmath/Shaders/CultMath.Affine.hlsl"
|
||||
RWStructuredBuffer<float4> Out;
|
||||
[numthreads(1,1,1)] void CSMain(uint3 id : SV_DispatchThreadID)
|
||||
{
|
||||
float2 r = cultmath_iv_add_missing(float2(1, 2), float2(3, 5));
|
||||
float2 a = cultmath_af_range(cultmath_af_add(cultmath_af_point(3), cultmath_af_point(5)));
|
||||
Out[0] = float4(r, a);
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"name": "CultMath.Smoke.Tests",
|
||||
"rootNamespace": "",
|
||||
"references": [ "UnityEngine.TestRunner", "UnityEditor.TestRunner" ],
|
||||
"includePlatforms": [ "Editor" ],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": true,
|
||||
"precompiledReferences": [ "nunit.framework.dll", "CultMath.dll" ],
|
||||
"autoReferenced": false,
|
||||
"defineConstraints": [ "UNITY_INCLUDE_TESTS" ],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
11
packages/cultmath/scripts/unity-smoke/Good.compute
Normal file
11
packages/cultmath/scripts/unity-smoke/Good.compute
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#pragma kernel CSMain
|
||||
#include "Packages/org.gamecult.cultmath/Shaders/CultMath.hlsl"
|
||||
#include "Packages/org.gamecult.cultmath/Shaders/CultMath.Interval.hlsl"
|
||||
#include "Packages/org.gamecult.cultmath/Shaders/CultMath.Affine.hlsl"
|
||||
RWStructuredBuffer<float4> Out;
|
||||
[numthreads(1,1,1)] void CSMain(uint3 id : SV_DispatchThreadID)
|
||||
{
|
||||
float2 r = cultmath_iv_add(float2(1, 2), float2(3, 5));
|
||||
float2 a = cultmath_af_range(cultmath_af_add(cultmath_af_point(3), cultmath_af_point(5)));
|
||||
Out[0] = float4(r, a);
|
||||
}
|
||||
44
packages/cultmath/scripts/unity-smoke/SmokeTests.cs
Normal file
44
packages/cultmath/scripts/unity-smoke/SmokeTests.cs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
using System;
|
||||
using CultMath;
|
||||
using NUnit.Framework;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
public class SmokeTests
|
||||
{
|
||||
// Compiles by FindKernel and dispatches on the device; false when the shader does not compile or the output is wrong.
|
||||
static bool CompilesAndRuns(string path)
|
||||
{
|
||||
var cs = AssetDatabase.LoadAssetAtPath<ComputeShader>(path);
|
||||
Assert.IsNotNull(cs, path);
|
||||
int k;
|
||||
try { k = cs.FindKernel("CSMain"); } catch (Exception e) { Debug.Log("SMOKE " + path + " FindKernel threw: " + e.Message); return false; }
|
||||
if (!cs.HasKernel("CSMain") || !cs.IsSupported(k)) { Debug.Log("SMOKE " + path + " kernel unusable"); return false; }
|
||||
var buf = new ComputeBuffer(1, 16);
|
||||
try
|
||||
{
|
||||
cs.SetBuffer(k, "Out", buf);
|
||||
cs.Dispatch(k, 1, 1, 1);
|
||||
var o = new Vector4[1]; buf.GetData(o);
|
||||
Debug.Log($"SMOKE {path} out=({o[0].x},{o[0].y},{o[0].z},{o[0].w}) gpu={SystemInfo.graphicsDeviceType}");
|
||||
return o[0].x == 4f && o[0].y == 7f && o[0].z <= 8f && o[0].w >= 8f && o[0].w - o[0].z < 1e-3f;
|
||||
}
|
||||
finally { buf.Release(); }
|
||||
}
|
||||
|
||||
[Test] public void CSharpIntervalAndAffineWork()
|
||||
{
|
||||
var r = math.iv_add(new float2(1, 2), new float2(3, 5));
|
||||
Assert.AreEqual(4f, r.x); Assert.AreEqual(7f, r.y);
|
||||
Assert.AreEqual(0f, math.snoise(new float3(0, 0, 0)));
|
||||
}
|
||||
|
||||
[Test] public void RealShaderCompilesAndDispatches() { Assert.IsTrue(CompilesAndRuns("Assets/Shaders/Good.compute")); }
|
||||
|
||||
[Test] public void BrokenShaderIsDetected()
|
||||
{
|
||||
LogAssert.ignoreFailingMessages = true;
|
||||
Assert.IsFalse(CompilesAndRuns("Assets/Shaders/Broken.compute"));
|
||||
}
|
||||
}
|
||||
84
packages/cultmath/scripts/unity-smoke/run-unity-smoke.ps1
Normal file
84
packages/cultmath/scripts/unity-smoke/run-unity-smoke.ps1
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
<#
|
||||
.SYNOPSIS
|
||||
The release smoke for the tracked org.gamecult.cultmath Unity package: imports it into a
|
||||
scratch project, compiles and dispatches a compute shader that includes the package's
|
||||
CultMath.Interval.hlsl and CultMath.Affine.hlsl on a real graphics device, and proves a
|
||||
deliberately broken shader is rejected.
|
||||
|
||||
.DESCRIPTION
|
||||
Run it on a Windows machine with a GPU, alone, before tagging cultmath-unity-v*. The scratch
|
||||
project is built outside the repository under -WorkRoot, references the package by a file: path,
|
||||
and is deleted afterwards (-Keep leaves it). Exit 0 only when all three tests of SmokeTests.cs
|
||||
passed: the C# calls, the real shader dispatched with the right output, and the broken control
|
||||
shader detected.
|
||||
|
||||
Never add -nographics. Without a device nothing compiles, and
|
||||
ShaderUtil.GetComputeShaderMessageCount reports 0 messages for a compute shader that calls an
|
||||
undeclared function until FindKernel or Dispatch compiles it, so a message-count check passes a
|
||||
broken shader. SmokeTests.cs compiles by FindKernel, dispatches, and reads the output back.
|
||||
|
||||
For a long run start it detached and poll the log, for example:
|
||||
Start-Process powershell -WindowStyle Hidden -ArgumentList '-File', '<this script>', '-UnityExe', '<Unity.exe>', '-WorkRoot', '<dir>'
|
||||
The script writes unity.pid and unity.log under the scratch root's logs folder (kept after the run).
|
||||
|
||||
.PARAMETER UnityExe
|
||||
Path to Unity.exe of the editor to test with (the cut that released 0.4.0 used 6000.3.24f1).
|
||||
.PARAMETER WorkRoot
|
||||
Directory outside the repository for the scratch project and logs. Default: a new folder under TEMP.
|
||||
.PARAMETER Keep
|
||||
Keep the scratch project instead of deleting it.
|
||||
#>
|
||||
param(
|
||||
[Parameter(Mandatory)] [string] $UnityExe,
|
||||
[string] $WorkRoot = (Join-Path $env:TEMP ("cultmath-unity-smoke-" + [guid]::NewGuid().ToString('N').Substring(0, 8))),
|
||||
[switch] $Keep
|
||||
)
|
||||
$ErrorActionPreference = 'Stop'
|
||||
if (-not (Test-Path -LiteralPath $UnityExe -PathType Leaf)) { throw "UnityExe not found: $UnityExe" }
|
||||
|
||||
$smoke = $PSScriptRoot
|
||||
$package = (Resolve-Path (Join-Path $smoke '..\..\unity\org.gamecult.cultmath')).Path
|
||||
$repoRoot = (git -C $smoke rev-parse --show-toplevel).Trim()
|
||||
$work = [IO.Path]::GetFullPath($WorkRoot)
|
||||
if ($work.StartsWith([IO.Path]::GetFullPath($repoRoot), [StringComparison]::OrdinalIgnoreCase)) {
|
||||
throw "WorkRoot must be outside the repository: $work"
|
||||
}
|
||||
$project = Join-Path $work 'project'
|
||||
$logs = Join-Path $work 'logs'
|
||||
New-Item -ItemType Directory -Force -Path $logs | Out-Null
|
||||
foreach ($d in 'Packages', 'Assets\Shaders', 'Assets\Tests') { New-Item -ItemType Directory -Force -Path (Join-Path $project $d) | Out-Null }
|
||||
|
||||
Copy-Item -LiteralPath (Join-Path $smoke 'Good.compute'), (Join-Path $smoke 'Broken.compute') -Destination (Join-Path $project 'Assets\Shaders')
|
||||
Copy-Item -LiteralPath (Join-Path $smoke 'SmokeTests.cs'), (Join-Path $smoke 'CultMath.Smoke.Tests.asmdef') -Destination (Join-Path $project 'Assets\Tests')
|
||||
|
||||
$packageUri = 'file:' + $package.Replace([string][char]92, '/')
|
||||
$manifest = [ordered]@{
|
||||
dependencies = [ordered]@{
|
||||
'com.unity.test-framework' = '1.6.0'
|
||||
'org.gamecult.cultmath' = $packageUri
|
||||
}
|
||||
}
|
||||
[IO.File]::WriteAllText((Join-Path $project 'Packages\manifest.json'), ($manifest | ConvertTo-Json -Depth 4), (New-Object Text.UTF8Encoding($false)))
|
||||
|
||||
$log = Join-Path $logs 'unity.log'
|
||||
$results = Join-Path $logs 'results.xml'
|
||||
$unityArgs = @('-batchmode', '-projectPath', $project, '-runTests', '-testPlatform', 'EditMode',
|
||||
'-testResults', $results, '-logFile', $log)
|
||||
$p = Start-Process -PassThru -FilePath $UnityExe -ArgumentList $unityArgs -WindowStyle Hidden
|
||||
$p.Id | Out-File (Join-Path $logs 'unity.pid') -Encoding ascii
|
||||
"unity pid=$($p.Id) log=$log"
|
||||
$p.WaitForExit()
|
||||
"unity exit=$($p.ExitCode)"
|
||||
|
||||
$ok = $false
|
||||
if (Test-Path -LiteralPath $results) {
|
||||
$cases = @(([xml](Get-Content -LiteralPath $results -Raw)).SelectNodes('//test-case'))
|
||||
$cases | ForEach-Object { "{0} {1}" -f $_.result, $_.name }
|
||||
$want = 'CSharpIntervalAndAffineWork', 'RealShaderCompilesAndDispatches', 'BrokenShaderIsDetected'
|
||||
$passed = @($cases | Where-Object { $_.result -eq 'Passed' } | ForEach-Object { ($_.name -split '\.')[-1] })
|
||||
$ok = (@($want | Where-Object { $passed -contains $_ }).Count -eq $want.Count)
|
||||
} else { 'no results file' }
|
||||
Get-Content -LiteralPath $log -ErrorAction SilentlyContinue | Select-String -CaseSensitive -Pattern '^SMOKE ' | ForEach-Object { $_.Line }
|
||||
|
||||
if (-not $Keep) { Remove-Item -LiteralPath $project -Recurse -Force }
|
||||
if ($ok) { 'SMOKE PASSED'; exit 0 } else { 'SMOKE FAILED'; exit 1 }
|
||||
Loading…
Reference in a new issue