Repository navigation
Expand file tree
/
Copy pathtests.ps1
More file actions
204 lines (167 loc) · 8.33 KB
/
Copy pathtests.ps1
File metadata and controls
204 lines (167 loc) · 8.33 KB
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
# Runs every test in .\tests, release and debug, compiled and under the JIT.
# .\tests.ps1 the compiler's default memory model (gc)
# .\tests.ps1 -Model rc -mm=rc, against the default library built for it; also $Env:TSLANG_MM
# A test whose first line starts with "// gc only" is skipped under any other model.
param([string]$Model = $Env:TSLANG_MM)
# The library paths the environment gives when the script starts. One it does not give is worked
# out again for each pass, release or debug: set once by the first pass, it made every later one
# link the release libraries, which a debug default library does not link with (LNK2038).
$GivenGcLibPath = $Env:GC_LIB_PATH
$GivenLlvmLibPath = $Env:LLVM_LIB_PATH
$GivenTslangLibPath = $Env:TSLANG_LIB_PATH
function Test([string]$config, [string]$mode, [string]$fileName)
{
$BUILD="debug"
$BUILD1="Debug"
$VER="-2026"
$LLVM_BUILD="Debug"
$ARCH="x64"
$DBG="--di --opt_level=0"
$OPTIONS="--nowarn"
if ($Model) {
$OPTIONS+=" -mm=$Model"
}
$TOOL="tslang"
$test=$fileName
if ($config -eq "release") {
$BUILD="release"
$BUILD1="release"
$LLVM_BUILD="Release"
$DBG=""
$OPTIONS+=" --opt --opt_level=3"
}
$SRC="."
$OUTPUT="."
if ($null -eq $Env:TOOL_PATH) {
$BUILD_PATH="..\TypeScriptCompiler\__build"
#$TOOL_PATH="..\TypeScriptCompiler\__build\$TOOL\windows-msbuild$VER-$BUILD\bin"
$TOOL_PATH="..\TypeScriptCompiler\__build\$TOOL\windows-msbuild$VER-release\bin"
$DEFAULTLIB_BUILD_PATH="..\TypeScriptCompilerDefaultLib\__build"
} else {
$TOOL_PATH=$Env:TOOL_PATH
$BUILD_PATH=$TOOL_PATH
# Compiled default lib is staged under .\__build\defaultlib\{dll,lib}\<target>\<mode>\<model>
# relative to the DefaultLib repo root (the tests working directory).
$DEFAULTLIB_BUILD_PATH=".\__build"
}
$Env:GC_LIB_PATH = if ($GivenGcLibPath) { $GivenGcLibPath } else { "$BUILD_PATH\gc\msbuild\$ARCH\$BUILD\$BUILD1" }
$Env:LLVM_LIB_PATH = if ($GivenLlvmLibPath) { $GivenLlvmLibPath } else { "$BUILD_PATH\llvm\msbuild\$ARCH\$BUILD\$BUILD1\lib" }
$Env:TSLANG_LIB_PATH = if ($GivenTslangLibPath) { $GivenTslangLibPath } else { "$BUILD_PATH\$TOOL\windows-msbuild$VER-$BUILD\lib" }
if ($null -eq $Env:DEFAULT_LIB_PAT) {
$Env:DEFAULT_LIB_PATH="$DEFAULTLIB_BUILD_PATH"
}
$DBG_ARGS = [string[]]$(if ($DBG -ne "") { $DBG -split " " } else { @() })
$OPTIONS_ARGS = [string[]]$(if ($OPTIONS -ne "") { $OPTIONS -split " " } else { @() })
$isX86 = ($Env:TSLANG_ARCH -eq "x86")
if ($isX86) {
# x86 mode hardcodes the sibling ..\TypeScriptCompiler layout for GC_LIB_PATH_X86 and
# TSLANG_LIB_PATH_X86 below, unlike the x64 path above: it ignores $Env:TOOL_PATH (and
# the $BUILD_PATH/$TOOL_PATH it would otherwise redirect) entirely, so a custom TOOL_PATH
# has no effect on which x86 gc/runtime libraries a x86 test run links against.
# 32-bit exes link statically; --shared-libs=...TypeScriptRuntime.dll below is an x64
# JIT-only DLL (tslang.cpp's clSharedLibs, read only by --emit=jit in jit.cpp) that
# --emit=exe never consumes, so it is dropped here rather than passed and ignored.
# --gc-lib-path/--tslang-lib-path/--default-lib-path are passed explicitly (not left to
# the $Env: defaults set above) so a value already sitting in the environment for this
# session can't leak into the x86 build; the compiler appends "x86" to the first two
# itself, and computes the x86 default-lib subdirectory under the same base path used
# for x64 (see getDefaultLibSubDir). --default-lib-path here is deliberate isolation,
# not a behavior change: it is the same $DEFAULTLIB_BUILD_PATH the $Env:DEFAULT_LIB_PATH
# default above already carries, so this only stops that env var (guarded by the
# `$Env:DEFAULT_LIB_PAT` typo elsewhere in this function, never fixed here) from being
# the sole thing standing between an x86 run and a stale x64 value.
$GC_LIB_PATH_X86="..\TypeScriptCompiler\3rdParty\gc\x64\$BUILD\lib"
$TSLANG_LIB_PATH_X86="..\TypeScriptCompiler\__build\tslang-runtime\$BUILD"
$ARCH_ARGS = @("-mtriple=i686-pc-windows-msvc", "--gc-lib-path=$GC_LIB_PATH_X86", "--tslang-lib-path=$TSLANG_LIB_PATH_X86", "--default-lib-path=$DEFAULTLIB_BUILD_PATH")
}
if ($mode -eq "compile") {
if ($isX86) {
$compile_error_output = ($compile_output = & $TOOL_PATH\$TOOL.exe @DBG_ARGS @OPTIONS_ARGS @ARCH_ARGS --emit=exe $SRC\tests\$test.ts) 2>&1
} else {
$compile_error_output = ($compile_output = & $TOOL_PATH\$TOOL.exe @DBG_ARGS @OPTIONS_ARGS --shared-libs=$TOOL_PATH\TypeScriptRuntime.dll --emit=exe $SRC\tests\$test.ts) 2>&1
}
$compile_code = $LASTEXITCODE
if ($compile_code -ne 0) {
Write-Host "Compile Error" -ForegroundColor Red
Write-Host "Output: $compile_output"
return $false
}
$run_error_output = ($run_output = & $SRC\tests\$test.exe) 2>&1
$run_code = $LASTEXITCODE
Get-ChildItem $SRC\tests\$test.* -Exclude *.ts | Remove-Item
}
if ($mode -eq "jit") {
$run_error_output = ($run_output = & $TOOL_PATH\$TOOL.exe @DBG_ARGS @OPTIONS_ARGS --shared-libs=$TOOL_PATH\TypeScriptRuntime.dll --emit=jit $SRC\tests\$test.ts) 2>&1
$run_code = $LASTEXITCODE
}
if (($run_error_output | Where-Object {$_.GetType().fullname.Contains("ErrorRecord")} | Measure-Object).Count -gt 0) {
return $false
}
if (($run_output -join "`n") -notmatch "ALL DONE") {
Write-Host "Run Error (no 'ALL DONE' marker)" -ForegroundColor Red
Write-Host "Output: $run_output"
return $false
}
return $true
}
# A test that needs the collector says so on its first line ("// gc only: WeakRef ..."): under
# rc, none or own the compiler rejects the collector's API, so it cannot pass there.
function Test-GcOnly([string]$path)
{
return (Get-Content $path -TotalCount 1) -match '^// gc only'
}
function Tests([string]$config, [string]$mode)
{
Write-Host "Testing..."
$count = (Get-ChildItem ".\tests" -Filter *.ts | Measure-Object).Count
$index = 0
$success = 0
$skipped = 0
$failedTests = @()
Get-ChildItem ".\tests" -Filter *.ts | Foreach-Object {
$index++
$testName = "$_ ".PadRight(40, '.')
Write-Host -NoNewline "$success/$count Test #$index : $testName "
if ($Model -and $Model -ne "gc" -and (Test-GcOnly $_.FullName)) {
$skipped++
Write-Host "Skipped (gc only)" -ForegroundColor Yellow
return
}
$time = (Measure-Command { $result = Test $config $mode $_.Basename }).TotalSeconds
$time = [math]::Round($time, 2).ToString("0.00")
if ($result -eq $true) {
$success++
Write-Host -NoNewline "Passed " -ForegroundColor Green
}
else {
$failedTests += $_.Name
Write-Host -NoNewline "Failed " -ForegroundColor Red
}
Write-Host "$time sec"
}
Get-ChildItem -Path $SRC\tests -Include *.pdb,*.ilk,*.exe | Remove-Item
Write-Host "Finished $config, $mode : $success/$count passed, $skipped skipped"
return $failedTests
}
$allFailedTests = @()
if ($Model) {
Write-Host "Memory model: $Model"
}
if ($Env:TSLANG_ARCH -eq "x86") {
# The JIT (jit.cpp) refuses x86 targets by design; only the two compile passes apply.
Write-Host "jit is host-only; skipped for x86" -ForegroundColor Yellow
$allFailedTests += Tests "release" "compile" | ForEach-Object { "release/compile: $_" }
$allFailedTests += Tests "debug" "compile" | ForEach-Object { "debug/compile: $_" }
} else {
$allFailedTests += Tests "release" "compile" | ForEach-Object { "release/compile: $_" }
$allFailedTests += Tests "release" "jit" | ForEach-Object { "release/jit: $_" }
$allFailedTests += Tests "debug" "compile" | ForEach-Object { "debug/compile: $_" }
$allFailedTests += Tests "debug" "jit" | ForEach-Object { "debug/jit: $_" }
}
if ($allFailedTests.Count -gt 0) {
Write-Host "Done. $($allFailedTests.Count) test(s) failed:" -ForegroundColor Red
$allFailedTests | ForEach-Object { Write-Host " - $_" -ForegroundColor Red }
exit 1
}
Write-Host "Done. All tests passed." -ForegroundColor Green
exit 0