-
Notifications
You must be signed in to change notification settings - Fork 6
/
2_0_test.ps1
327 lines (274 loc) · 11.9 KB
/
2_0_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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<# Code by MSP-Greg
Runs Ruby tests with STDOUT & STDERR sent to two files, allows setting a max
time, so if a test freezes, it can be stopped.
#>
$exit_code = 0
#————————————————————————————————————————————————————————————————————— Kill-Proc
# Kills a process by first looping thru child & grandchild processes and
# stopping them, then stops passed process
function Kill-Proc($proc) {
$processes = @()
$p_pid = $proc.id
$temp = $(Get-CimInstance -ClassName Win32_Process | where {$_.ProcessId -eq $p_pid} )
$parents = @($temp)
while ($parents -and $parents.length -gt 0) {
$processes += $parents
$children = @()
foreach ($parent in $parents) {
[int32]$p_pid = $parent.ProcessId
$children += $(Get-CimInstance -ClassName Win32_Process |
where {$_.ParentProcessId -eq $p_pid} )
}
$parents = $children
}
$t = -1 * ($processes.length)
$r_processes = $processes[-1..$t]
Write-Host "Process pid parent" -ForegroundColor $fc
foreach ($process in $r_processes) {
$t = "{0,-14} {1,5} {2,5}" -f @($process.Name, $process.ProcessId, $process.ParentProcessId)
Write-Host $t
}
foreach ($process in $r_processes) {
$id = $process.ProcessId
if (!$process.HasExited) {
Stop-Process -Id $id -Force -ErrorAction SilentlyContinue
sleep (0.1)
}
}
Write-Host "Processes Killed!" -ForegroundColor $fc
}
#—————————————————————————————————————————————————————————————————————— Run-Proc
# Runs a process with a timeout setting, sets STDOUT & STDERR to files
# Outputs running dots to console
function Run-Proc {
Param( [string]$StdOut , [string]$exe , [string]$Title ,
[string]$StdErr , [string]$e_args , [string]$Dir , [int]$TimeLimit
)
EchoC "$($dash * 35) $Title" yel
if ($TimeLimit -eq $null -or $TimeLimit -eq 0 ) {
echo "Need TimeLimit!"
exit
}
$msg = "Time Limit {0,8:n1} s {1}" -f @($TimeLimit, $(Get-Date -Format mm:ss))
echo $msg
$start = Get-Date
$status = ''
$proc = Start-Process $exe -ArgumentList $e_args `
-RedirectStandardOutput $d_logs/$StdOut `
-RedirectStandardError $d_logs/$StdErr `
-WorkingDirectory $Dir `
-NoNewWindow -PassThru
$handle = $proc.Handle
Wait-Process -Id $proc.id -Timeout $TimeLimit -ea 0 -ev froze
if ($froze) {
EchoC "Exceeded time limit..." yel
$handle = $null
Kill-Proc $proc
$status = " (frozen)"
}
$diff = New-TimeSpan -Start $start -End $(Get-Date)
$msg = "Test Time {0,8:n1}" -f @($diff.TotalSeconds)
Write-Host $msg -NoNewLine
if ($proc.ExitCode -eq 0) {
EchoC " passed" grn
} else {
EchoC " failed" red
$status = " (failed)"
}
$script:time_info += ("{0:mm}:{0:ss} {1}`n" -f @($diff, "$Title$status"))
$handle = $null
$proc = $null
Stop-Process -Name ruby -Force -ErrorAction SilentlyContinue
}
#———————————————————————————————————————————————————————————————————————— Finish
# cleanup, save artifacts, etc
function Finish {
# test time info message and file
$diff = New-TimeSpan -Start $m_start -End $(Get-Date)
$script:time_info += ("{0:mm}:{0:ss} {1}`n" -f @($diff, "Total"))
$fn = "$d_logs/time_log_tests.log"
[IO.File]::WriteAllText($fn, $script:time_info, $UTF8)
if ($is_av) {
Add-AppveyorMessage -Message "Time Log Test" -Details $script:time_info
}
# remove zero length log files, typically stderr files
$zero_length_files = Get-ChildItem -Path $d_logs -Include *.log -Recurse |
where {$_.length -eq 0}
foreach ($file in $zero_length_files) {
Remove-Item -Path $file -Force -ErrorAction SilentlyContinue
}
$env:PATH = "$d_install/bin;$d_repo/git/cmd;$base_path"
# used in 2_1_test_script.rb
$env:PS_ENC = [Console]::OutputEncoding.WebName.toUpper()
EchoC "$dash_hdr Test Results" yel
cd $d_repo
# script checks test results, determines whether build is good or not,
# saves artifacts and adds messages to build
ruby.exe 2_1_test_script.rb $exit_code
$exit += ($LastExitCode -and $LastExitCode -ne 0)
ruby.exe -v -ropenssl -e "puts 'Build ' + OpenSSL::OPENSSL_VERSION, 'Runtime ' + OpenSSL::OPENSSL_LIBRARY_VERSION"
if ($is_actions) {
echo "Actions ImageVersion: $env:ImageVersion"
} elseif ($is_av) {
echo "Build worker image: $env:APPVEYOR_BUILD_WORKER_IMAGE"
}
$env:Path = $orig_path
if ($exit -ne 0) { exit 1 }
}
#————————————————————————————————————————————————————————————————————— BasicTest
function BasicTest {
$env:PATH = "$d_install/bin;$base_path"
Run-Proc `
-exe "ruby.exe" `
-e_args "--disable=gems ruby_runner.rb -r -v --tty=no" `
-StdOut "test_basic.log" `
-StdErr "test_basic_err.log" `
-Title "test-basic (basictest)" `
-Dir "$d_ruby/basictest" `
-TimeLimit 20
}
#————————————————————————————————————————————————————————————————— BootStrapTest
function BootStrapTest {
$env:PATH = "$d_install/bin;$base_path"
Run-Proc `
-exe $ruby_exe `
-e_args "--disable=gems runner.rb --ruby=`"$ruby_exe --disable=gems`" -v" `
-StdOut "test_bootstrap.log" `
-StdErr "test_bootstrap_err.log" `
-Title "btest (bootstraptest)" `
-Dir "$d_ruby/bootstraptest" `
-TimeLimit 200
}
#—————————————————————————————————————————————————————————————————————— Test-All
function Test-All {
# Standard Ruby CI doesn't run this test, remove for better comparison
# $remove_test = "$d_ruby/test/ruby/enc/test_case_comprehensive.rb"
# if (Test-Path -Path $remove_test -PathType Leaf) { Remove-Item -Path $remove_test }
# copy items from build folder that are needed for test-all
if (Test-Path -Path "$d_build/.ext/$rarch/-test-" -PathType Container) {
$ruby_so = "$d_install/lib/ruby/$abi/$rarch"
Copy-Item "$d_build/.ext/$rarch/-test-" $ruby_so -Recurse
New-Item -Path "$ruby_so/-test-/win32/dln" -ItemType Directory 1> $null
Copy-Item "$d_build/ext/-test-/win32/dln/dlntest.dll" `
"$ruby_so/-test-/win32/dln/dlntest.dll"
}
$env:PATH = "$d_install/bin;$d_repo/git/cmd;$base_path"
$env:RUBY_FORCE_TEST_JIT = '1'
$env:RUBYGEMS_TEST_PATH = "$d_repo/ruby/test/rubygems"
# for rubygems/test_bundled_ca.rb
$env:TEST_SSL = '1'
if ($build_sys -ne 'mswin') {
$args = "--disable=gems -rdevkit ./runner.rb -X ./.excludes -n !/memory_leak/ -j $jobs" + `
" -v --show-skip --retry --job-status=normal --timeout-scale=1.5"
} else {
$args = "--disable=gems ./runner.rb -X ./.excludes -n !/memory_leak/ -j $jobs" + `
" -v --show-skip --retry --job-status=normal --timeout-scale=1.5"
}
# find absolute path for ruby repo
$test_dir = ((Get-Item "$d_ruby").LinkType -eq $null) ?
"$d_ruby/test" :
"$(Get-Item "$d_ruby" | Select-Object -ExpandProperty Target)/test"
Run-Proc `
-exe $ruby_exe `
-e_args $args `
-StdOut "test_all.log" `
-StdErr "test_all_err.log" `
-Title "test-all" `
-Dir "$test_dir" `
-TimeLimit 3000
# comment out below to allow full testing of Appveyor artifact
# Remove-Item -Path "$d_install/lib/ruby/$abi/$rarch/-test-" -Recurse
}
#——————————————————————————————————————————————————————————————————— Test-Reline
function Test-Reline {
$env:PATH = "$d_install/bin;$d_repo/git/cmd;$base_path"
$args = "--disable=gems -rrbconfig ./runner.rb -v --show-skip reline"
Run-Proc `
-exe $ruby_exe `
-e_args $args `
-StdOut "test_reline.log" `
-StdErr "test_reline_err.log" `
-Title "test-reline" `
-Dir "$d_ruby/test" `
-TimeLimit 20
}
#————————————————————————————————————————————————————————————————————————— MSpec
function MSpec {
$env:PATH = "$d_install/bin;$d_repo/git/cmd;$base_path"
if ($build_sys -ne 'mswin') {
$args = "-rdevkit ../mspec/bin/mspec -j -fd -I$d_ruby/tool/lib"
} else {
$args = "../mspec/bin/mspec -j -fd -I$d_ruby/tool/lib"
}
Run-Proc `
-exe "ruby.exe" `
-e_args $args `
-StdOut "test_mspec.log" `
-StdErr "test_mspec_err.log" `
-Title "test-mspec" `
-Dir "$d_ruby/spec/ruby" `
-TimeLimit 480
}
#————————————————————————————————————————————————————————————————————————— setup
cd $PSScriptRoot
. ./0_common.ps1 $args
Set-Variables
# apply patches for testing
Run-Patches @('ruby', 'patches_basic_boot', 'patches_spec', 'patches_test')
$ruby_exe = "$d_install/bin/ruby.exe"
$abi = &$ruby_exe -e "print RbConfig::CONFIG['ruby_version']"
$script:time_info = ''
$env:PATH = "$d_install/bin;$no_ruby_path"
if ($env:DESTDIR) { Remove-Item env:\DESTDIR }
if ($env:BUNDLER_VERSION) { Remove-Item env:\BUNDLER_VERSION }
#————————————————————————————————————————————————————————————————— start testing
# PATH is set in each test function
# assumes symlink folder exists, some tests may not be happy with a space in
# git's path
$env:GIT = "$d_repo/git/cmd/git.exe"
$m_start = Get-Date
EchoC $($dash * 92) yel
ruby -ropenssl -e "puts RUBY_DESCRIPTION, OpenSSL::OPENSSL_LIBRARY_VERSION"
EchoC "$dash_hdr Install `'tz`' gems" yel
gem install `"timezone:>=1.3.16`" `"tzinfo:>=2.0.4`" `"tzinfo-data:>=1.2022.1`" --no-document --conservative --norc --no-user-install
# CLI-Test
EchoC "$dash_hdr CLI Test" yel
echo "bundle version: $(bundle version)" ; $exit_code += [int](0 + $LastExitCode)
echo "gem --version: $(gem --version)" ; $exit_code += [int](0 + $LastExitCode)
echo "irb --version: $(irb --version)" ; $exit_code += [int](0 + $LastExitCode)
echo "racc --version: $(racc --version)" ; $exit_code += [int](0 + $LastExitCode)
echo "rake --version: $(rake --version)" ; $exit_code += [int](0 + $LastExitCode)
echo "rbs --version: $(rbs --version)" ; $exit_code += [int](0 + $LastExitCode)
echo "rdbg --version: $(rdbg --version)" ; $exit_code += [int](0 + $LastExitCode)
echo "rdoc --version: $(rdoc --version)" ; $exit_code += [int](0 + $LastExitCode)
if ($build_sys -ne 'mswin') {
echo "ridk version:"
ridk version
}
echo ''
# Encoding
EchoC "$dash_hdr Encoding" yel
echo "Encoding.find('external') : $(ruby -e `"puts Encoding.find('external')`")"
echo "Encoding.find('filesystem'): $(ruby -e `"puts Encoding.find('filesystem')`")"
echo "Encoding.find('locale') : $(ruby -e `"puts Encoding.find('locale')`")"
echo "Encoding.default_external : $(ruby -e `"puts Encoding.default_external`")"
echo ''
EchoC "$dash_hdr Run Tests" yel
BasicTest
sleep 2
BootStrapTest
sleep 2
if ($build_sys -ne 'mswin') {
if (Test-Path -Path $d_install/lib/ruby/$abi/$rarch/readline.so -PathType Leaf ) {
ren "$d_install/lib/ruby/$abi/$rarch/readline.so" "readline.so_"
}
}
Test-All
sleep 5
Test-Reline
sleep 5
MSpec
if (Test-Path -Path $d_install/lib/ruby/$abi/$rarch/readline.so -PathType Leaf ) {
ren "$d_install/lib/ruby/$abi/$rarch/readline.so" "readline.so_"
}
Finish