-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ps1
249 lines (217 loc) · 9.9 KB
/
test.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
param (
[switch]$ExitOnRCFailure = $false,
[switch]$IncludePreprocessorQuirkFiles = $false,
[switch]$IncludeWin32WillCompileErrorFiles = $false,
[switch]$ExcludeWindres = $false,
[switch]$ExcludeLLVMRC = $false,
[switch]$ExcludeResinator = $false,
[switch]$ExcludeZigRC = $false,
[switch]$ErrorOnAnyDiscrepancies = $false,
[switch]$ErrorOnAnyLikelyPanics = $false,
[switch]$MinGWCompat = $false
)
. ".\_common.ps1"
Ensure-HasCommand "rc.exe"
$result_log_file = "results.log"
$null = New-Item "$result_log_file" -ItemType File -Force
function Write-Log {
param ( $message )
# for some reason Add-Content was sporadically failing with 'Stream was not readable'
# so this is used instead
[System.IO.File]::AppendAllText($result_log_file, "$message`n")
}
$compilers = @{
rc = @{ cmd = "rc.exe"; successes = 0; errors = 0; }
}
$alt_compilers = @("resinator", "windres", "llvm-rc", "zig")
foreach($alt_compiler in $alt_compilers)
{
if ($ExcludeResinator -and $alt_compiler -eq "resinator") { continue }
if ($ExcludeWindres -and $alt_compiler -eq "windres") { continue }
if ($ExcludeLLVMRC -and $alt_compiler -eq "llvm-rc") { continue }
if ($ExcludeZigRC -and $alt_compiler -eq "zig") { continue }
if (Test-HasCommand $alt_compiler) {
$compilers[$alt_compiler] = @{ cmd = $alt_compiler; successes = 0; expected_errors = 0; unexpected_errors = 0; missing_errors = 0; different_outputs = 0; likely_panics = 0; }
Write-Output "Found RC compiler: $alt_compiler"
if ($alt_compiler -eq "windres") {
# Set up extra windres includes using shortname paths from INCLUDE
#
# There are two hacks/workarounds happening here:
# 1. windres does not search the paths in the INCLUDE environment variable,
# so we manually provide each one via the command line
# 2. windres can't handle spaces in -I include paths at all, so we must
# get the 'short name' for all INCLUDE paths (e.g. `C:\Program Files` ->
# `C:\PROGRA~1`)
#
# This is necessary to allow windres to successfully compile .rc files that
# include .rc files from the Windows SDK, e.g. `afxres.rc`
$extra_windres_include_paths = $env:INCLUDE -split ";" | ForEach-Object { (New-Object -ComObject Scripting.FileSystemObject).GetFolder($_).ShortPath }
}
}
}
if ($compilers.Count -eq 1 -and -not $ExitOnRCFailure) {
Write-Error "No alternate RC compilers found in the PATH. To test with only the Win32 RC compiler, -ExitOnRCFailure is required."
exit 1
}
Write-Output ""
Write-Log "=================================================`n"
$num_processed = 0
$files = Get-ChildItem "Windows-classic-samples\Samples" -Recurse -Include *.rc
foreach($f in $files) {
if (-not $IncludePreprocessorQuirkFiles -and (Test-Win32PreprocessorQuirk $f)) { continue }
if (-not $IncludeWin32WillCompileErrorFiles -and (Test-Win32WillCompileError $f)) { continue }
$dirname = Split-Path $f.FullName
$outfilename = $f.BaseName + ".expected.res"
$rcfilename = $f.Name
$fulloutfile = "$dirname\$outfilename"
$extra_include_paths = @()
if ($dirname -match "oledb_conformance") {
$pos = $dirname.IndexOf("oledb_conformance")
$include_dir_parent = $dirname.Substring(0, $pos + "oledb_conformance".Length)
$extra_include_paths += "$include_dir_parent\include"
}
if ($dirname -match "Win7Samples\\netds\\eap\\eaphost") {
$extra_include_paths += "..\inc"
}
$extra_rc_args = $extra_include_paths | ForEach-Object {"/I", "`"$_`""}
if ($MinGWCompat) {
# Necessary to avoid a compile error in MinGW's vadefs.h which expects either
# _MSC_VER or __GNUC__ to be defined. Additionally, one of _M_IA64, _M_IX86,
# or _M_AMD64 must be defined if _MSC_VER is defined.
$extra_rc_args += " /D_MSC_VER /D_M_AMD64"
# Avoid an error in winnt.h
$extra_rc_args += " /D__x86_64__"
}
$command_string = "rc.exe /fo `"$outfilename`" $extra_rc_args `"$rcfilename`" 2>&1"
Push-Location "$dirname"
$output = & cmd /S /C "$command_string"
$exitcode = $LASTEXITCODE
Pop-Location
Write-Log ("Cwd: $dirname")
Write-Log ("Rc: $rcfilename`n")
Write-Log ("Command: $command_string")
Write-Log ("Command output (exit code: " + $exitcode + "):`n---")
Write-Log ($output -join "`n")
Write-Log "---`n"
if ($ExitOnRCFailure -and $exitcode -ne 0) {
Write-Output $f.FullName
Write-Output $exitcode
Write-Output $output
Exit 1
} else {
if ($exitcode -eq 0) {
$compilers["rc"]["successes"]++;
} else {
$compilers["rc"]["errors"]++;
}
}
foreach ($alt_compiler in $alt_compilers) {
if (-not $compilers[$alt_compiler]) { continue }
$compiler_cmd = $compilers[$alt_compiler].cmd
if ($alt_compiler -eq "zig") {
$compiler_cmd = $compiler_cmd + " rc"
}
$actual_outfilename = $f.BaseName + "." + $alt_compiler + ".res"
$actual_fulloutfile = "$dirname\$actual_outfilename"
if ($alt_compiler -eq "resinator" -or $alt_compiler -eq "zig") {
# We want to set /:auto-includes none so that we test the INCLUDE env var, and
# allow e.g. using the INCLUDE env var to test different sets of headers (for example,
# setting INCLUDE to only have the paths to MinGW headers)
$actual_command_string = "$compiler_cmd /fo `"$actual_outfilename`" /:auto-includes none $extra_rc_args `"$rcfilename`" 2>&1"
} elseif ($alt_compiler -ne "windres") {
$actual_command_string = "$compiler_cmd /fo `"$actual_outfilename`" $extra_rc_args `"$rcfilename`" 2>&1"
} else {
$all_extra_include_paths = $extra_include_paths + $extra_windres_include_paths
$extra_windres_args = $all_extra_include_paths | ForEach-Object {"-I", "`"$_`""}
$actual_command_string = "$compiler_cmd $extra_windres_args `"$rcfilename`" `"$actual_outfilename`" 2>&1"
}
Write-Log ("Command: $actual_command_string")
Push-Location "$dirname"
$actual_output = & cmd /S /C "$actual_command_string"
$actual_exitcode = $LASTEXITCODE
Pop-Location
Write-Log ("Command output (exit code: " + $actual_exitcode + "):`n---")
Write-Log ($actual_output -join "`n")
Write-Log "---"
if ($actual_exitcode -ne 0 -and $actual_exitcode -ne 1) {
Write-Log "LIKELY PANIC: Non-zero and non-one exit code"
$compilers[$alt_compiler].likely_panics++
}
if ($exitcode -ne 0 -and $actual_exitcode -ne 0) {
$compilers[$alt_compiler].expected_errors++
} elseif ($actual_exitcode -ne 0 -and $exitcode -eq 0) {
$compilers[$alt_compiler].unexpected_errors++
Write-Log "DISCREPANCY: Expected success, but got compile error"
} elseif ($exitcode -ne 0 -and $actual_exitcode -eq 0) {
$compilers[$alt_compiler].missing_errors++
Write-Log "DISCREPANCY: Expected error, but didn't get one"
} else {
$null = & "fc.exe" /B "$fulloutfile" "$actual_fulloutfile"
$compare_exitcode = $LASTEXITCODE
if ($compare_exitcode -ne 0) {
$compilers[$alt_compiler].different_outputs++
Write-Log "DISCREPANCY: Different .res outputs"
} else {
$compilers[$alt_compiler].successes++
}
}
Write-Log "`n"
if (Test-Path -Path "$actual_fulloutfile") {
Remove-Item -Path "$actual_fulloutfile"
}
}
# clean up .res
if (Test-Path -Path "$fulloutfile") {
Remove-Item -Path "$fulloutfile"
}
$num_processed++;
Write-Host -NoNewline "`rProcessed $num_processed .rc files"
Write-Log "=================================================`n`n"
}
$any_discrepancies = $false
$any_likely_panics = $false
Write-Output ""
foreach ($alt_compiler in $alt_compilers) {
if (-not $compilers[$alt_compiler]) { continue }
$compiler_name = $alt_compiler
if ($compiler_name -eq "zig") {
$compiler_name = "zig rc"
}
Write-Output "`n---------------------------"
Write-Output " $compiler_name"
Write-Output "---------------------------"
$results = $compilers[$alt_compiler]
if ($results.likely_panics -ne 0) {
Write-Output "`ncheck $result_log_file for lines with LIKELY PANIC:"
Write-Output "likely crashes/panics: $($results.likely_panics)"
$any_likely_panics = $true
}
$total_discrepancies = $results.unexpected_errors + $results.missing_errors + $results.different_outputs
if ($total_discrepancies -ne 0) {
Write-Output "`n$total_discrepancies .rc files processed with discrepancies"
Write-Output "different .res outputs: $($results.different_outputs)"
Write-Output "unexpected compile errors: $($results.unexpected_errors)"
Write-Output "missing compile errors: $($results.missing_errors)"
$any_discrepancies = $true
}
$total_conforming = $results.successes + $results.expected_errors
if ($total_conforming -ne 0) {
Write-Output "`n$total_conforming .rc files processed without discrepancies"
if ($results.successes -ne 0) {
Write-Output "identical .res outputs: $($results.successes)"
}
if ($results.expected_errors -ne 0) {
Write-Output "expected compile errors: $($results.expected_errors)"
}
}
}
Write-Output "`n---------------------------"
Write-Output "`nSee $result_log_file for details about each file`n"
if ($any_discrepancies -and $ErrorOnAnyDiscrepancies) {
Write-Error "Found at least one discrepancy"
exit 1
}
if ($any_likely_panics -and $ErrorOnAnyLikelyPanics) {
Write-Error "Found at least one likely panic"
exit 1
}