blob: ce60a967d8bc199164091b026f9bd248a979e704 [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 .
25cp ..\..\vktrace\$dPath\vulkan_trace.dll
David Pinedo1405a432015-06-30 15:37:50 -060026cp ..\..\demos\$dPath\cube.exe .
27cp ..\..\demos\*.png .
Cody Northropfb207af2015-08-31 11:33:35 -060028cp ..\..\demos\*.spv .
Mark Lobodzinskif39d70c2015-08-14 14:24:50 -060029cp ..\..\loader\$dPath\vulkan.0.dll .
David Pinedo1405a432015-06-30 15:37:50 -060030cp ..\..\layers\$dPath\VKLayerScreenShot.dll .
Cody Northropfb207af2015-08-31 11:33:35 -060031cp ..\..\layers\$dPath\screenshot.json .
David Pinedo1405a432015-06-30 15:37:50 -060032
33# Change PATH to the temp directory
34$oldpath = $Env:PATH
35$Env:PATH = $pwd
Cody Northropfb207af2015-08-31 11:33:35 -060036
37# Set up some modified env vars
Cody Northropbc6ecfa2015-08-14 10:59:35 -060038$Env:VK_LAYER_PATH = $pwd
David Pinedo1405a432015-06-30 15:37:50 -060039
Cody Northropfb207af2015-08-31 11:33:35 -060040# Temporarily set ScreenShot layer by hand until these are worked out
41$Env:_VK_SCREENSHOT = 1
42$Env:VK_INSTANCE_LAYERS = "ScreenShot"
43$Env:VK_DEVICE_LAYERS = "ScreenShot"
44
David Pinedo1405a432015-06-30 15:37:50 -060045# Do a trace and replay
Cody Northropfb207af2015-08-31 11:33:35 -060046& vktrace -o c01.vktrace -s 1 -p cube -a "--c 10" -l0 vulkan_trace.dll > trace.sout 2> trace.serr
David Pinedo1405a432015-06-30 15:37:50 -060047rename-item -path 1.ppm -newname 1-trace.ppm
Cody Northropfb207af2015-08-31 11:33:35 -060048& vkreplay -s 1 -t c01.vktrace > replay.sout 2> replay.serr
David Pinedo1405a432015-06-30 15:37:50 -060049rename-item -path 1.ppm -newname 1-replay.ppm
50
51# Force a failure - for testing this script
52#cp vulkan.dll 1-replay.ppm
53#rm 1-trace.ppm
54#rm 1-replay.ppm
55
56# Restore PATH
57$Env:PATH = $oldpath
58
Cody Northropfb207af2015-08-31 11:33:35 -060059if ($exitstatus -eq 0) {
60 # Check that two screenshots were created
61 if (!(Test-Path 1-trace.ppm) -or !(Test-Path 1-replay.ppm)) {
62 echo 'Trace file does not exist'
63 write-host -background black -foreground red "[ FAILED ] " -nonewline;
64 $exitstatus = 1
65 }
66}
67
68if ($exitstatus -eq 0) {
69 # ensure the trace and replay snapshots are identical
David Pinedo1405a432015-06-30 15:37:50 -060070 fc.exe /b 1-trace.ppm 1-replay.ppm > $null
71 if (!(Test-Path 1-trace.ppm) -or !(Test-Path 1-replay.ppm) -or $LastExitCode -eq 1) {
Cody Northropfb207af2015-08-31 11:33:35 -060072 echo 'Trace files do not match'
73 write-host -background black -foreground red "[ FAILED ] " -nonewline;
74 $exitstatus = 1
David Pinedo1405a432015-06-30 15:37:50 -060075 }
76}
Cody Northropfb207af2015-08-31 11:33:35 -060077
78# check the average pixel value of each screenshot to ensure something plausible was written
79if ($exitstatus -eq 0) {
80 $trace_mean = (convert 1-trace.ppm -format "%[mean]" info:)
81 $replay_mean = (convert 1-replay.ppm -format "%[mean]" info:)
82 $version = (identify -version)
83
84 # normalize the values so we can support Q8 and Q16 imagemagick installations
85 if ($version -match "Q8") {
86 $trace_mean = $trace_mean / 255 # 2^8-1
87 $replay_mean = $replay_mean / 255 # 2^8-1
88 } else {
89 $trace_mean = $trace_mean / 65535 # 2^16-1
90 $replay_mean = $replay_mean / 65535 # 2^16-1
91 }
92
93 # if either screenshot is too bright or too dark, it either failed, or is a bad test
94 if (($trace_mean -lt 0.10) -or ($trace_mean -gt 0.90)){
95 echo ''
96 echo 'Trace screenshot failed mean check, must be in range [0.1, 0.9]'
97 write-host 'Detected mean:' $trace_mean
98 echo ''
99 write-host -background black -foreground red "[ FAILED ] " -nonewline;
100 $exitstatus = 1
101 }
102 if (($replay_mean -lt 0.10) -or ($replay_mean -gt 0.90)){
103 echo ''
104 echo 'Replay screenshot failed mean check, must be in range [0.1, 0.9]'
105 write-host 'Detected mean:' $replay_mean
106 echo ''
107 write-host -background black -foreground red "[ FAILED ] " -nonewline;
108 $exitstatus = 1
109 }
110}
111
112# if we passed all the checks, the test is good
113if ($exitstatus -eq 0) {
114 write-host -background black -foreground green "[ PASSED ] " -nonewline;
115}
116
Mark Lobodzinskif39d70c2015-08-14 14:24:50 -0600117write-host "vktracereplay.ps1: Vktrace trace/replay"
David Pinedo1405a432015-06-30 15:37:50 -0600118write-host
119if ($exitstatus) {
120 echo '1 FAILED TEST'
121}
122
Cody Northropfb207af2015-08-31 11:33:35 -0600123# cleanup
David Pinedo1405a432015-06-30 15:37:50 -0600124cd ..
125rm -recurse -force vktracereplay_tmp > $null 2> $null
Cody Northropfb207af2015-08-31 11:33:35 -0600126Remove-Item Env:\VK_LAYER_PATH
127Remove-Item Env:\_VK_SCREENSHOT
128Remove-Item Env:\VK_INSTANCE_LAYERS
129Remove-Item Env:\VK_DEVICE_LAYERS
David Pinedo1405a432015-06-30 15:37:50 -0600130exit $exitstatus