1+
2+ . $PSScriptRoot \dependencies.ps1
3+
4+ function WaitUnity ([System.Diagnostics.ProcessStartInfo ] $processInfo , $targetName , $unityProjectPath ) {
5+ $appdata = " $env: LOCALAPPDATA "
6+ $logPath = " $appdata \Unity\Editor\Editor.log"
7+ $processLogsPath = " $unityProjectPath \TestResults"
8+
9+ $processInfo.FileName = " $Env: UNITY_2021_3_17 \Unity.exe"
10+ $processInfo.RedirectStandardError = " $processLogsPath \Error.log"
11+ $processInfo.RedirectStandardOutput = " $processLogsPath \Output.log"
12+ $processInfo.UseShellExecute = $false
13+
14+ $process = New-Object System.Diagnostics.Process
15+ $process.StartInfo = $processInfo
16+ $process.Start () | Out-Null
17+ Write-Host " Starting Unity project at $ ( Resolve-Path $unityProjectPath ) (Id = $ ( $process.Id ) ) ..."
18+
19+ $time = 0
20+ $displayTime = 10
21+ while (-Not ($process.HasExited )) {
22+ if (-not (Get-Process - Id $process.Id - ErrorAction SilentlyContinue)) {
23+ $process | Stop-Process - Force
24+ }
25+ else {
26+ Write-Host " Unity (Id = $ ( $process.Id ) ) work in progress... Don't run away ! (time : $time s)"
27+ Start-Sleep - Seconds $displayTime ;
28+ $time += $displayTime
29+ }
30+
31+
32+ # If a key was pressed during the loop execution, check to see if it was CTRL-C (aka "3")
33+ if ($Host.UI.RawUI.KeyAvailable -and (3 -eq [int ]$Host.UI.RawUI.ReadKey (" AllowCtrlC,IncludeKeyUp,NoEcho" ).Character)) {
34+ Write-Host " "
35+ Write-Warning " CTRL-C was used - Shutting down any running jobs before exiting the script."
36+
37+ # Force end of started process
38+ $process | Stop-Process - Force
39+ }
40+ }
41+
42+ if ($process.HasExited ) {
43+ # Keep a local copy of Unity logs for each targets
44+ $unityLogsCopy = " $processLogsPath \$targetName .log"
45+ Copy-Item $logPath $unityLogsCopy
46+
47+ # Unity does not send valid keycode at the end of process operation
48+ # Instead use Unity ouput to try to get information about the operation
49+ if ($null -ne $ (Select-String - Path $logPath - Pattern " another Unity instance is running" - SimpleMatch) -Or $process.ExitCode -ne 0 ) {
50+ Write-Host " Unity report an error. More information can be found in Unity editor logs." - ForegroundColor Red
51+
52+ if ($process.ExitCode -eq 1 ) {
53+ Write-Host " Unity builder command line interface report and error. Operation canceled" - ForegroundColor Red
54+ }
55+ }
56+ else {
57+ $time = $process.ExitTime
58+ Write-Host " Unity operation done in $time seconds" - ForegroundColor Green
59+ }
60+
61+ # Logs for each target
62+ Write-Host " Logs available at $ ( Resolve-Path $unityLogsCopy ) "
63+ }
64+ else {
65+ Write-Host " User cancel request." - ForegroundColor Yellow
66+ }
67+
68+ return $process.ExitCode
69+ }
70+
71+
72+
73+ function RunUnitTestWithAPI ($apiName ) {
74+ [OutputType ([Boolean ])]
75+ $xmlPath = " $Env: INTEROP_UNITY_CUDA_UNITY_PROJECT_ROOT \TestResults\test_results.xml"
76+
77+ # if we see a previous xml containing result, we delete it
78+ if ((Test-Path - Path $xmlPath - PathType Leaf) -eq 1 ) {
79+ Remove-Item $xmlPath
80+ }
81+
82+ # https://docs.unity3d.com/Packages/[email protected] /manual/reference-command-line.html 83+ $cmdArgs = " -runTests" , " -projectPath" , " `" $Env: INTEROP_UNITY_CUDA_UNITY_PROJECT_ROOT `" " ,
84+ " -batchmode" ,
85+ " -force-$apiName " ,
86+ " -testResults" , " `" $xmlPath `" " ,
87+ " -testPlatform" , " PlayMode"
88+
89+
90+
91+ $pinfo = New-Object System.Diagnostics.ProcessStartInfo
92+ $pinfo.Arguments = $cmdArgs
93+ WaitUnity $pinfo " UnitTest_InteropUnityCUDA" $Env: INTEROP_UNITY_CUDA_UNITY_PROJECT_ROOT
94+
95+ [xml ]$c = (Get-Content $xmlPath )
96+ # Display test results
97+ $details = $c .' test-run' .' test-suite' .' test-suite' .' test-suite' .' test-case' | Select-Object name, duration, result
98+ $details | Format-Table | Out-String | ForEach-Object { Write-Host $_ }
99+ Write-Host " Passed " $c .' test-run' .' passed' " /" $c .' test-run' .' total'
100+ $resultTest = $c .' test-run' .' passed' -eq $c .' test-run' .' total'
101+ if ($resultTest -eq $True ) {
102+ Write-Host " Unit tests with $apiName have passed !" - ForegroundColor Green
103+ }
104+ else {
105+ Write-Host " Unit tests with $apiName have failed !" - ForegroundColor Red
106+
107+ }
108+ $resultTest
109+ }
110+
111+ $supportedGraphicsAPI = @ (" glcore" , " d3d11" ) # , "d3d12"
112+
113+ Write-Host " "
114+ Write-Host " ------------------------------" - ForegroundColor DarkMagenta
115+ Write-Host " Running : Unit tests" - ForegroundColor DarkMagenta
116+ Write-Host " ------------------------------" - ForegroundColor DarkMagenta
117+
118+ $testsPassed = $True
119+ foreach ($api in $supportedGraphicsAPI ) {
120+ Write-Host " Run test with graphics api : $api "
121+ $result = RunUnitTestWithAPI $api
122+ $testsPassed = $testsPassed -and $result [1 ]
123+ }
124+
125+ if ($testsPassed -eq $True ) {
126+ Write-Host " All unit tests have passed !" - ForegroundColor Green
127+ }
128+ else {
129+ Write-Host " Some Unit tests with $apiName have failed !" - ForegroundColor Red
130+
131+ }
132+
133+ Exit $testsPassed
0 commit comments