blob: d77b252c2f2520735fbbe0b4db305e85ae226a28 [file] [log] [blame]
Mark Lobodzinskif39d70c2015-08-14 14:24:50 -06001# Powershell script for running the vktrace trace/replay auto test
David Pinedo1405a432015-06-30 15:37:50 -06002# To run this test:
3# cd <this-dir>
Mark Lobodzinskif39d70c2015-08-14 14:24:50 -06004# powershell C:\src\LoaderAndTools\vktracereplay.ps1 [-Debug]
Cody Northropfb207af2015-08-31 11:33:35 -06005$exitstatus = 0
David Pinedo1405a432015-06-30 15:37:50 -06006
7if ($args[0] -eq "-Debug") {
8 $dPath = "Debug"
9} else {
10 $dPath = "Release"
11}
12
13write-host -background black -foreground green "[ RUN ] " -nonewline
Mark Lobodzinskif39d70c2015-08-14 14:24:50 -060014write-host "vktracereplay.ps1: Vktrace trace/replay"
David Pinedo1405a432015-06-30 15:37:50 -060015
David Pinedo1405a432015-06-30 15:37:50 -060016# Create a temp directory to run the test in
17rm -recurse -force vktracereplay_tmp > $null 2> $null
18new-item vktracereplay_tmp -itemtype directory > $null 2> $null
19
20# Copy everything we need into the temp directory, so we
21# can make sure we are using the correct dll and exe files
22cd vktracereplay_tmp
Cody Northropfb207af2015-08-31 11:33:35 -060023cp ..\..\vktrace\$dPath\vkreplay.exe .
24cp ..\..\vktrace\$dPath\vktrace.exe .
David Pinedo1405a432015-06-30 15:37:50 -060025cp ..\..\demos\$dPath\cube.exe .
Tony Barboura26fb7d2015-09-21 15:17:33 -060026cp ..\..\demos\*.ppm .
Cody Northropfb207af2015-08-31 11:33:35 -060027cp ..\..\demos\*.spv .
Cody Northropb229f972015-09-09 13:01:34 -060028cp ..\..\loader\$dPath\vulkan-0.dll .
David Pinedo1405a432015-06-30 15:37:50 -060029cp ..\..\layers\$dPath\VKLayerScreenShot.dll .
Cody Northropfb207af2015-08-31 11:33:35 -060030cp ..\..\layers\$dPath\screenshot.json .
Cody Northrop3513c152015-09-18 10:52:42 -060031cp ..\..\layers\$dPath\vktrace_layer.dll .
32cp ..\..\layers\$dPath\vktrace_layer.json .
David Pinedo1405a432015-06-30 15:37:50 -060033
34# Change PATH to the temp directory
35$oldpath = $Env:PATH
36$Env:PATH = $pwd
Cody Northropfb207af2015-08-31 11:33:35 -060037
38# Set up some modified env vars
Cody Northropbc6ecfa2015-08-14 10:59:35 -060039$Env:VK_LAYER_PATH = $pwd
David Pinedo1405a432015-06-30 15:37:50 -060040
41# Do a trace and replay
Jon Ashburnb9470052015-09-21 14:01:41 -060042& vktrace -o c01.vktrace -s 1 -p cube -a "--c 10" > trace.sout 2> trace.serr
David Pinedo1405a432015-06-30 15:37:50 -060043rename-item -path 1.ppm -newname 1-trace.ppm
Cody Northropfb207af2015-08-31 11:33:35 -060044& vkreplay -s 1 -t c01.vktrace > replay.sout 2> replay.serr
David Pinedo1405a432015-06-30 15:37:50 -060045rename-item -path 1.ppm -newname 1-replay.ppm
46
47# Force a failure - for testing this script
48#cp vulkan.dll 1-replay.ppm
49#rm 1-trace.ppm
50#rm 1-replay.ppm
51
52# Restore PATH
53$Env:PATH = $oldpath
54
Cody Northropfb207af2015-08-31 11:33:35 -060055if ($exitstatus -eq 0) {
56 # Check that two screenshots were created
57 if (!(Test-Path 1-trace.ppm) -or !(Test-Path 1-replay.ppm)) {
58 echo 'Trace file does not exist'
59 write-host -background black -foreground red "[ FAILED ] " -nonewline;
60 $exitstatus = 1
61 }
62}
63
64if ($exitstatus -eq 0) {
65 # ensure the trace and replay snapshots are identical
David Pinedo1405a432015-06-30 15:37:50 -060066 fc.exe /b 1-trace.ppm 1-replay.ppm > $null
67 if (!(Test-Path 1-trace.ppm) -or !(Test-Path 1-replay.ppm) -or $LastExitCode -eq 1) {
Cody Northropfb207af2015-08-31 11:33:35 -060068 echo 'Trace files do not match'
69 write-host -background black -foreground red "[ FAILED ] " -nonewline;
70 $exitstatus = 1
David Pinedo1405a432015-06-30 15:37:50 -060071 }
72}
Cody Northropfb207af2015-08-31 11:33:35 -060073
74# check the average pixel value of each screenshot to ensure something plausible was written
75if ($exitstatus -eq 0) {
76 $trace_mean = (convert 1-trace.ppm -format "%[mean]" info:)
77 $replay_mean = (convert 1-replay.ppm -format "%[mean]" info:)
78 $version = (identify -version)
79
80 # normalize the values so we can support Q8 and Q16 imagemagick installations
81 if ($version -match "Q8") {
82 $trace_mean = $trace_mean / 255 # 2^8-1
83 $replay_mean = $replay_mean / 255 # 2^8-1
84 } else {
85 $trace_mean = $trace_mean / 65535 # 2^16-1
86 $replay_mean = $replay_mean / 65535 # 2^16-1
87 }
88
89 # if either screenshot is too bright or too dark, it either failed, or is a bad test
90 if (($trace_mean -lt 0.10) -or ($trace_mean -gt 0.90)){
91 echo ''
92 echo 'Trace screenshot failed mean check, must be in range [0.1, 0.9]'
93 write-host 'Detected mean:' $trace_mean
94 echo ''
95 write-host -background black -foreground red "[ FAILED ] " -nonewline;
96 $exitstatus = 1
97 }
98 if (($replay_mean -lt 0.10) -or ($replay_mean -gt 0.90)){
99 echo ''
100 echo 'Replay screenshot failed mean check, must be in range [0.1, 0.9]'
101 write-host 'Detected mean:' $replay_mean
102 echo ''
103 write-host -background black -foreground red "[ FAILED ] " -nonewline;
104 $exitstatus = 1
105 }
106}
107
108# if we passed all the checks, the test is good
109if ($exitstatus -eq 0) {
110 write-host -background black -foreground green "[ PASSED ] " -nonewline;
111}
112
Mark Lobodzinskif39d70c2015-08-14 14:24:50 -0600113write-host "vktracereplay.ps1: Vktrace trace/replay"
David Pinedo1405a432015-06-30 15:37:50 -0600114write-host
115if ($exitstatus) {
116 echo '1 FAILED TEST'
117}
118
Cody Northropfb207af2015-08-31 11:33:35 -0600119# cleanup
David Pinedo1405a432015-06-30 15:37:50 -0600120cd ..
121rm -recurse -force vktracereplay_tmp > $null 2> $null
Cody Northropfb207af2015-08-31 11:33:35 -0600122Remove-Item Env:\VK_LAYER_PATH
David Pinedo1405a432015-06-30 15:37:50 -0600123exit $exitstatus