author | Claus Gittinger <cg@exept.de> |
Tue, 26 Mar 2019 18:29:27 +0100 | |
changeset 2179 | 9d14571951e7 |
parent 1447 | 2351db93aa5b |
child 1500 | d406a10b2965 |
permissions | -rw-r--r-- |
1276
343771ee1f6b
class: RegressionTests::VMCrashTestCase
Stefan Vogel <sv@exept.de>
parents:
1199
diff
changeset
|
1 |
"{ Encoding: utf8 }" |
343771ee1f6b
class: RegressionTests::VMCrashTestCase
Stefan Vogel <sv@exept.de>
parents:
1199
diff
changeset
|
2 |
|
1447 | 3 |
"{ Package: 'stx:goodies/regression' }" |
1172 | 4 |
|
5 |
"{ NameSpace: RegressionTests }" |
|
6 |
||
7 |
TestCase subclass:#VMCrashTestCase |
|
8 |
instanceVariableNames:'' |
|
9 |
classVariableNames:'EXIT_CODE_SUCCESS EXIT_CODE_FAILURE EXIT_CODE_ERROR' |
|
10 |
poolDictionaries:'' |
|
11 |
category:'tests-Regression-Abstract' |
|
12 |
! |
|
13 |
||
14 |
!VMCrashTestCase class methodsFor:'documentation'! |
|
15 |
||
16 |
documentation |
|
17 |
" |
|
18 |
A specialized abstract test case class for writing |
|
19 |
VM crash tests. The test is run in separate process |
|
20 |
if it eventually crashes the VM, it won't take whole test |
|
21 |
suite with it. |
|
22 |
||
1189
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
23 |
Each test case *must* be annotated by one <spawn:> annotation, |
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
24 |
argument must be either `true` of `false`. If `true` then the |
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
25 |
test is run in a freshly started VM. If `false`, test is run |
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
26 |
in the same VM. |
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
27 |
|
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
28 |
As this is meant as a base class for regression tests that used to |
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
29 |
kill the VM, normally you should annotate tests with <spawn: true> |
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
30 |
|
1172 | 31 |
[author:] |
1447 | 32 |
Jan Vrany <jan.vrany@fit.cvut.cz> |
1172 | 33 |
|
34 |
[instance variables:] |
|
35 |
||
36 |
[class variables:] |
|
37 |
||
38 |
[see also:] |
|
39 |
||
40 |
" |
|
41 |
! ! |
|
42 |
||
43 |
!VMCrashTestCase class methodsFor:'initialization'! |
|
44 |
||
45 |
initialize |
|
46 |
"Invoked at system start or when the class is dynamically loaded." |
|
47 |
||
48 |
"/ please change as required (and remove this comment) |
|
49 |
||
50 |
EXIT_CODE_SUCCESS := 0. |
|
51 |
EXIT_CODE_FAILURE := 1. |
|
52 |
EXIT_CODE_ERROR := 2. |
|
53 |
||
54 |
"Modified: / 05-09-2014 / 18:17:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
55 |
! ! |
|
56 |
||
57 |
!VMCrashTestCase class methodsFor:'testing'! |
|
58 |
||
59 |
isAbstract |
|
60 |
^ self == RegressionTests::VMCrashTestCase |
|
61 |
! ! |
|
62 |
||
1189
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
63 |
!VMCrashTestCase methodsFor:'accessing'! |
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
64 |
|
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
65 |
timeout |
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
66 |
"Returns a default timeout (sec) for the test. |
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
67 |
If nil is returned, no timeout enforced. |
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
68 |
|
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
69 |
Note that the timeout is set only when running under |
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
70 |
report runner, interactive tools does not use it" |
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
71 |
|
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
72 |
| method | |
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
73 |
method := self class lookupMethodFor: testSelector. |
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
74 |
method annotationsAt:#timeout: do:[:annotation| |
1447 | 75 |
^annotation arguments first |
1189
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
76 |
]. |
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
77 |
^60"sec - default timeout" |
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
78 |
|
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
79 |
"Created: / 08-09-2014 / 13:00:45 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
80 |
! ! |
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
81 |
|
1172 | 82 |
!VMCrashTestCase methodsFor:'running'! |
83 |
||
84 |
runCase |
|
1189
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
85 |
"Perform the testcase. |
1172 | 86 |
|
1189
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
87 |
If testcase is annotated by <spawn: false> the test is run in the |
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
88 |
very same VM. If <spawn: true>, a new VM is started and the testcase |
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
89 |
in run in that new VM" |
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
90 |
|
1194
01167ea2ad14
More support for debugging - file out also some scripts useful when debugging the test.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1189
diff
changeset
|
91 |
| tempDir testcaseFile exe args script environment outputFile output pid blocker status spawn | |
1172 | 92 |
|
1189
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
93 |
spawn := (self class lookupMethodFor: testSelector) annotationAt: #spawn:. |
1447 | 94 |
spawn isNil ifTrue:[ |
95 |
self error: 'No <spawn:> annotation'. |
|
1189
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
96 |
]. |
1447 | 97 |
(spawn argumentAt: 1) == false ifTrue:[ |
98 |
^ super runCase. |
|
99 |
] ifFalse:[ |
|
100 |
(spawn argumentAt: 1) ~~ true ifTrue:[ |
|
101 |
self error: 'Argument to <spawn:> must be either `true` or `false`'. |
|
102 |
] |
|
1172 | 103 |
]. |
104 |
||
105 |
[ |
|
1447 | 106 |
tempDir := Filename newTemporary. |
107 |
tempDir makeDirectory. |
|
108 |
testcaseFile := tempDir / ((Smalltalk fileNameForClass: self class) , '.st'). |
|
109 |
self class fileOutAs: testcaseFile. |
|
1172 | 110 |
|
1447 | 111 |
script := 'Smalltalk packagePath: %1. |
112 |
Smalltalk loadPackage:%2. |
|
113 |
Smalltalk fileIn: %3. |
|
114 |
(%4 selector: %5) runCaseInternal.' |
|
115 |
bindWith: Smalltalk packagePath asArray storeString |
|
116 |
with: self class package storeString |
|
117 |
with: testcaseFile pathName storeString |
|
118 |
with: self class name |
|
119 |
with: testSelector storeString. |
|
1172 | 120 |
|
1447 | 121 |
exe := OperatingSystem pathOfSTXExecutable. |
122 |
args := { exe . '--abortOnSEGV' . '--execute' . ( tempDir / 'run.st' ) pathName }. |
|
1172 | 123 |
|
1447 | 124 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
125 |
args := String streamContents:[:s| |
|
126 |
args |
|
127 |
do:[:each | s nextPut:$"; nextPutAll: each; nextPut: $"] |
|
128 |
separatedBy: [ s space ] |
|
129 |
] |
|
130 |
]. |
|
1172 | 131 |
|
1447 | 132 |
outputFile := tempDir / 'output.txt'. |
133 |
output := outputFile writeStream. |
|
1172 | 134 |
|
1447 | 135 |
"/ Now, spit out some helper files that for debugging. |
136 |
( tempDir / 'run.st' ) writingFileDo:[ :f | |
|
137 |
f nextPutAll: script. |
|
138 |
]. |
|
139 |
environment := OperatingSystem isUNIXlike |
|
140 |
ifTrue:[OperatingSystem getEnvironment copy] |
|
141 |
ifFalse:[environment := Dictionary new]. |
|
142 |
blocker := Semaphore new. |
|
1172 | 143 |
|
1447 | 144 |
Processor monitor:[ |
145 |
pid := OperatingSystem exec: exe withArguments:args |
|
146 |
environment:environment |
|
147 |
fileDescriptors:{0 . output fileDescriptor . output fileDescriptor } |
|
148 |
fork:true |
|
149 |
newPgrp:false |
|
150 |
inDirectory: Filename currentDirectory pathName |
|
151 |
] action: [ :s | |
|
152 |
status := s. |
|
153 |
blocker signal. |
|
154 |
]. |
|
1172 | 155 |
|
1447 | 156 |
output close. |
1172 | 157 |
|
1447 | 158 |
pid isNil ifTrue:[ |
159 |
self error: 'Failed to spawn test'. |
|
160 |
^ self. |
|
161 |
]. |
|
1172 | 162 |
|
1447 | 163 |
blocker wait. |
1172 | 164 |
|
1447 | 165 |
status code == EXIT_CODE_FAILURE ifTrue:[ |
166 |
(outputFile notNil and:[ outputFile exists ]) ifTrue:[ |
|
167 |
Stdout nextPutAll: '== TEST FAILED: '; nextPutAll: testSelector; nextPutLine:' =='. |
|
168 |
outputFile readingFileDo:[:s| |
|
169 |
[ s atEnd ] whileFalse:[ |
|
170 |
Stdout nextPutLine: s nextLine. |
|
171 |
]. |
|
172 |
]. |
|
173 |
]. |
|
174 |
self assert: false description: 'Assertion failed, see log'. |
|
175 |
]. |
|
176 |
(status code == EXIT_CODE_ERROR or:[status status == #signal]) ifTrue:[ |
|
177 |
(outputFile notNil and:[ outputFile exists ]) ifTrue:[ |
|
178 |
Stdout nextPutAll: '== TEST ERROR: '; nextPutAll: testSelector; nextPutLine:' =='. |
|
179 |
outputFile readingFileDo:[:s| |
|
180 |
[ s atEnd ] whileFalse:[ |
|
181 |
Stdout nextPutLine: s nextLine. |
|
182 |
]. |
|
183 |
]. |
|
184 |
]. |
|
185 |
self error: 'Error occured'. |
|
186 |
]. |
|
187 |
] ensure:[ |
|
188 |
(tempDir notNil and:[tempDir exists]) ifTrue:[ |
|
189 |
[ |
|
190 |
tempDir recursiveRemove. |
|
191 |
] on: Error do:[:ex | |
|
192 |
OperatingSystem isMSWINDOWSlike ifFalse:[ |
|
193 |
ex reject. |
|
194 |
]. |
|
195 |
] |
|
196 |
]. |
|
1172 | 197 |
]. |
198 |
||
1189
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
199 |
" |
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
200 |
VMCrashTestCase run:#test_infrastructure |
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
201 |
" |
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
202 |
|
1172 | 203 |
"Created: / 04-09-2014 / 18:13:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1199
81fcf185ef45
class: RegressionTests::VMCrashTestCase
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1194
diff
changeset
|
204 |
"Modified: / 19-09-2014 / 16:43:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1172 | 205 |
! |
206 |
||
207 |
runCaseInternal |
|
208 |
[ |
|
1447 | 209 |
super runCase. |
210 |
Stdout cr; |
|
211 |
nextPutAll: 'PASSED'; cr. |
|
1172 | 212 |
] on: TestResult failure do:[:failure | |
1447 | 213 |
Stdout cr; |
214 |
nextPutAll: 'FAILURE: '; nextPutAll: failure description; cr. |
|
215 |
Smalltalk exit: EXIT_CODE_FAILURE. |
|
1172 | 216 |
] on: TestResult exError do:[:error | |
1447 | 217 |
Stdout cr; |
218 |
nextPutAll: 'ERROR: '; nextPutAll: error description; cr. |
|
219 |
Smalltalk exit: EXIT_CODE_ERROR. |
|
1172 | 220 |
]. |
221 |
||
222 |
"Created: / 04-09-2014 / 17:41:38 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
223 |
"Modified: / 05-09-2014 / 18:37:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
224 |
! ! |
|
225 |
||
226 |
!VMCrashTestCase methodsFor:'tests - infrastructure'! |
|
227 |
||
228 |
test_infrastructure |
|
229 |
" |
|
230 |
VMCrashTestCase run:#test_infrastructure |
|
231 |
" |
|
1189
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
232 |
<spawn: false> |
1172 | 233 |
|
234 |
| result | |
|
235 |
||
236 |
result := self class run: #tst_pass. |
|
237 |
self assert: result passedCount = 1. |
|
238 |
self assert: result failureCount = 0. |
|
239 |
self assert: result errorCount = 0. |
|
240 |
||
241 |
result := self class run: #tst_fail. |
|
242 |
self assert: result passedCount = 0. |
|
243 |
self assert: result failureCount = 1. |
|
244 |
self assert: result errorCount = 0. |
|
245 |
||
246 |
result := self class run: #tst_error. |
|
247 |
self assert: result passedCount = 0. |
|
248 |
self assert: result failureCount = 0. |
|
249 |
self assert: result errorCount = 1. |
|
250 |
||
251 |
" |
|
1447 | 252 |
VMCrashTestCase run: #tst_crash. |
1172 | 253 |
" |
254 |
result := self class run: #tst_crash. |
|
255 |
self assert: result passedCount = 0. |
|
256 |
self assert: result failureCount = 0. |
|
257 |
self assert: result errorCount = 1. |
|
258 |
||
259 |
"Created: / 05-09-2014 / 18:22:26 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1189
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
260 |
"Modified: / 08-09-2014 / 12:26:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1172 | 261 |
! |
262 |
||
263 |
tst_crash |
|
1189
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
264 |
|
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
265 |
<spawn: true> |
1447 | 266 |
|
267 |
| bytes | |
|
1172 | 268 |
|
1194
01167ea2ad14
More support for debugging - file out also some scripts useful when debugging the test.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1189
diff
changeset
|
269 |
Stdout nextPutLine: 'Going to crash now!!'. |
01167ea2ad14
More support for debugging - file out also some scripts useful when debugging the test.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1189
diff
changeset
|
270 |
|
1172 | 271 |
bytes := ExternalBytes address: 16r10 size: 100. |
272 |
bytes byteAt: 1 put: 10. |
|
273 |
||
274 |
"Created: / 05-09-2014 / 18:24:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1194
01167ea2ad14
More support for debugging - file out also some scripts useful when debugging the test.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1189
diff
changeset
|
275 |
"Modified: / 16-09-2014 / 20:30:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1172 | 276 |
! |
277 |
||
278 |
tst_error |
|
1189
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
279 |
<spawn: true> |
1172 | 280 |
self error:'Error' |
281 |
||
282 |
"Created: / 05-09-2014 / 18:20:46 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1189
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
283 |
"Modified: / 08-09-2014 / 12:26:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1172 | 284 |
! |
285 |
||
286 |
tst_fail |
|
1189
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
287 |
<spawn: true> |
1172 | 288 |
self assert: false. |
289 |
||
290 |
"Created: / 05-09-2014 / 18:20:24 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1189
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
291 |
"Modified: / 08-09-2014 / 12:26:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1172 | 292 |
! |
293 |
||
1447 | 294 |
tst_pass |
1189
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
295 |
<spawn: true> |
1172 | 296 |
|
297 |
"Created: / 05-09-2014 / 18:20:51 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1189
6c1c1eefa063
Added regression test #test_java_initialize
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
1172
diff
changeset
|
298 |
"Modified: / 08-09-2014 / 12:26:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1172 | 299 |
! ! |
300 |
||
301 |
!VMCrashTestCase class methodsFor:'documentation'! |
|
302 |
||
303 |
version |
|
304 |
^ '$Header$' |
|
305 |
! |
|
306 |
||
307 |
version_CVS |
|
308 |
^ '$Header$' |
|
309 |
! ! |
|
310 |
||
311 |
||
312 |
VMCrashTestCase initialize! |