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