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 |
|
|
21 |
[author:]
|
|
22 |
Jan Vrany <jan.vrany@fit.cvut.cz>
|
|
23 |
|
|
24 |
[instance variables:]
|
|
25 |
|
|
26 |
[class variables:]
|
|
27 |
|
|
28 |
[see also:]
|
|
29 |
|
|
30 |
"
|
|
31 |
! !
|
|
32 |
|
|
33 |
!VMCrashTestCase class methodsFor:'initialization'!
|
|
34 |
|
|
35 |
initialize
|
|
36 |
"Invoked at system start or when the class is dynamically loaded."
|
|
37 |
|
|
38 |
"/ please change as required (and remove this comment)
|
|
39 |
|
|
40 |
EXIT_CODE_SUCCESS := 0.
|
|
41 |
EXIT_CODE_FAILURE := 1.
|
|
42 |
EXIT_CODE_ERROR := 2.
|
|
43 |
|
|
44 |
"Modified: / 05-09-2014 / 18:17:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
45 |
! !
|
|
46 |
|
|
47 |
!VMCrashTestCase class methodsFor:'testing'!
|
|
48 |
|
|
49 |
isAbstract
|
|
50 |
^ self == RegressionTests::VMCrashTestCase
|
|
51 |
! !
|
|
52 |
|
|
53 |
!VMCrashTestCase methodsFor:'running'!
|
|
54 |
|
|
55 |
runCase
|
|
56 |
"Actually peform the testcase in a separate process"
|
|
57 |
|
|
58 |
| testcaseFile exe args script environment outputFile output pid blocker status |
|
|
59 |
|
|
60 |
"/ A hack to run infrastructure test...
|
|
61 |
(testSelector == #test_infrastructure) ifTrue:[
|
|
62 |
^ super runCase.
|
|
63 |
].
|
|
64 |
|
|
65 |
[
|
|
66 |
testcaseFile := Filename newTemporary.
|
|
67 |
self class fileOutAs: testcaseFile.
|
|
68 |
|
|
69 |
script := 'Smalltalk packagePath: %1.
|
|
70 |
Smalltalk loadPackage:%2.
|
|
71 |
Smalltalk fileIn: %3.
|
|
72 |
(%4 selector: %5) runCaseInternal.'
|
|
73 |
bindWith: Smalltalk packagePath asArray storeString
|
|
74 |
with: self class package storeString
|
|
75 |
with: testcaseFile pathName storeString
|
|
76 |
with: self class name
|
|
77 |
with: testSelector storeString.
|
|
78 |
|
|
79 |
exe := OperatingSystem pathOfSTXExecutable.
|
|
80 |
args := { exe . '--abortOnSEGV' . '--eval' . script }.
|
|
81 |
|
|
82 |
OperatingSystem isMSWINDOWSlike ifTrue:[
|
|
83 |
args := String streamContents:[:s|
|
|
84 |
args
|
|
85 |
do:[:each | s nextPut:$"; nextPutAll: each; nextPut: $"]
|
|
86 |
separatedBy: [ s space ]
|
|
87 |
]
|
|
88 |
].
|
|
89 |
|
|
90 |
outputFile := Filename newTemporary.
|
|
91 |
output := outputFile writeStream.
|
|
92 |
|
|
93 |
environment := OperatingSystem isUNIXlike
|
|
94 |
ifTrue:[OperatingSystem getEnvironment copy]
|
|
95 |
ifFalse:[environment := Dictionary new].
|
|
96 |
blocker := Semaphore new.
|
|
97 |
|
|
98 |
Processor monitor:[
|
|
99 |
pid := OperatingSystem exec: exe withArguments:args
|
|
100 |
environment:environment
|
|
101 |
fileDescriptors:{0 . output fileDescriptor . output fileDescriptor }
|
|
102 |
fork:true
|
|
103 |
newPgrp:false
|
|
104 |
inDirectory: Filename currentDirectory pathName
|
|
105 |
] action: [ :s |
|
|
106 |
status := s.
|
|
107 |
blocker signal.
|
|
108 |
].
|
|
109 |
|
|
110 |
output close.
|
|
111 |
|
|
112 |
pid isNil ifTrue:[
|
|
113 |
self error: 'Failed to spawn test'.
|
|
114 |
^ self.
|
|
115 |
].
|
|
116 |
|
|
117 |
blocker wait.
|
|
118 |
|
|
119 |
status code == EXIT_CODE_FAILURE ifTrue:[
|
|
120 |
(outputFile notNil and:[ outputFile exists ]) ifTrue:[
|
|
121 |
Stdout nextPutAll: '== TEST FAILED: '; nextPutAll: testSelector; nextPutLine:' =='.
|
|
122 |
outputFile readingFileDo:[:s|
|
|
123 |
[ s atEnd ] whileFalse:[
|
|
124 |
Stdout nextPutLine: s nextLine.
|
|
125 |
].
|
|
126 |
].
|
|
127 |
].
|
|
128 |
self assert: false description: 'Assertion failed, see log'.
|
|
129 |
].
|
|
130 |
(status code == EXIT_CODE_ERROR or:[status status == #signal]) ifTrue:[
|
|
131 |
(outputFile notNil and:[ outputFile exists ]) ifTrue:[
|
|
132 |
Stdout nextPutAll: '== TEST ERROR: '; nextPutAll: testSelector; nextPutLine:' =='.
|
|
133 |
outputFile readingFileDo:[:s|
|
|
134 |
[ s atEnd ] whileFalse:[
|
|
135 |
Stdout nextPutLine: s nextLine.
|
|
136 |
].
|
|
137 |
].
|
|
138 |
].
|
|
139 |
self error: 'Error occured'.
|
|
140 |
].
|
|
141 |
] ensure:[
|
|
142 |
(testcaseFile notNil and:[testcaseFile exists]) ifTrue:[
|
|
143 |
testcaseFile remove.
|
|
144 |
].
|
|
145 |
outputFile
|
|
146 |
].
|
|
147 |
|
|
148 |
"Created: / 04-09-2014 / 18:13:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
149 |
"Modified: / 05-09-2014 / 19:03:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
150 |
!
|
|
151 |
|
|
152 |
runCaseInternal
|
|
153 |
[
|
|
154 |
super runCase.
|
|
155 |
Stdout cr;
|
|
156 |
nextPutAll: 'PASSED'; cr.
|
|
157 |
] on: TestResult failure do:[:failure |
|
|
158 |
Stdout cr;
|
|
159 |
nextPutAll: 'FAILURE: '; nextPutAll: failure description; cr.
|
|
160 |
Smalltalk exit: EXIT_CODE_FAILURE.
|
|
161 |
] on: TestResult exError do:[:error |
|
|
162 |
Stdout cr;
|
|
163 |
nextPutAll: 'ERROR: '; nextPutAll: error description; cr.
|
|
164 |
Smalltalk exit: EXIT_CODE_ERROR.
|
|
165 |
].
|
|
166 |
|
|
167 |
"Created: / 04-09-2014 / 17:41:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
168 |
"Modified: / 05-09-2014 / 18:37:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
169 |
! !
|
|
170 |
|
|
171 |
!VMCrashTestCase methodsFor:'tests - infrastructure'!
|
|
172 |
|
|
173 |
test_infrastructure
|
|
174 |
"
|
|
175 |
VMCrashTestCase run:#test_infrastructure
|
|
176 |
"
|
|
177 |
|
|
178 |
| result |
|
|
179 |
|
|
180 |
result := self class run: #tst_pass.
|
|
181 |
self assert: result passedCount = 1.
|
|
182 |
self assert: result failureCount = 0.
|
|
183 |
self assert: result errorCount = 0.
|
|
184 |
|
|
185 |
result := self class run: #tst_fail.
|
|
186 |
self assert: result passedCount = 0.
|
|
187 |
self assert: result failureCount = 1.
|
|
188 |
self assert: result errorCount = 0.
|
|
189 |
|
|
190 |
result := self class run: #tst_error.
|
|
191 |
self assert: result passedCount = 0.
|
|
192 |
self assert: result failureCount = 0.
|
|
193 |
self assert: result errorCount = 1.
|
|
194 |
|
|
195 |
"
|
|
196 |
VMCrashTestCase run: #tst_crash.
|
|
197 |
"
|
|
198 |
result := self class run: #tst_crash.
|
|
199 |
self assert: result passedCount = 0.
|
|
200 |
self assert: result failureCount = 0.
|
|
201 |
self assert: result errorCount = 1.
|
|
202 |
|
|
203 |
"Created: / 05-09-2014 / 18:22:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
204 |
!
|
|
205 |
|
|
206 |
tst_crash
|
|
207 |
| bytes |
|
|
208 |
|
|
209 |
bytes := ExternalBytes address: 16r10 size: 100.
|
|
210 |
bytes byteAt: 1 put: 10.
|
|
211 |
|
|
212 |
"Created: / 05-09-2014 / 18:24:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
213 |
!
|
|
214 |
|
|
215 |
tst_error
|
|
216 |
self error:'Error'
|
|
217 |
|
|
218 |
"Created: / 05-09-2014 / 18:20:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
219 |
!
|
|
220 |
|
|
221 |
tst_fail
|
|
222 |
self assert: false.
|
|
223 |
|
|
224 |
"Created: / 05-09-2014 / 18:20:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
225 |
!
|
|
226 |
|
|
227 |
tst_pass
|
|
228 |
|
|
229 |
"Created: / 05-09-2014 / 18:20:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
230 |
! !
|
|
231 |
|
|
232 |
!VMCrashTestCase class methodsFor:'documentation'!
|
|
233 |
|
|
234 |
version
|
|
235 |
^ '$Header$'
|
|
236 |
!
|
|
237 |
|
|
238 |
version_CVS
|
|
239 |
^ '$Header$'
|
|
240 |
! !
|
|
241 |
|
|
242 |
|
|
243 |
VMCrashTestCase initialize!
|