100
|
1 |
"{ Package: 'exept:regression' }"
|
|
2 |
|
|
3 |
"{ NameSpace: RegressionTests }"
|
|
4 |
|
249
|
5 |
TestCase subclass:#ContextTest2
|
|
6 |
instanceVariableNames:'exceptionObject'
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'tests-Regression'
|
|
10 |
!
|
|
11 |
|
|
12 |
Notification subclass:#MyNotification
|
100
|
13 |
instanceVariableNames:''
|
|
14 |
classVariableNames:''
|
|
15 |
poolDictionaries:''
|
249
|
16 |
privateIn:ContextTest2
|
100
|
17 |
!
|
|
18 |
|
|
19 |
|
239
|
20 |
!ContextTest2 methodsFor:'helpers'!
|
100
|
21 |
|
250
|
22 |
call1
|
|
23 |
^ self call2
|
|
24 |
!
|
|
25 |
|
|
26 |
call2
|
|
27 |
^ self call3
|
|
28 |
!
|
|
29 |
|
|
30 |
call3
|
|
31 |
|ttt|
|
|
32 |
|
|
33 |
ttt := thisContext.
|
|
34 |
^ ttt sender sender
|
|
35 |
!
|
|
36 |
|
147
|
37 |
downToNextSegmentThenDo:aBlock
|
249
|
38 |
self
|
|
39 |
downToSegment:(Processor activeProcess numberOfStackSegments + 1)
|
|
40 |
thenDo:aBlock
|
147
|
41 |
|
|
42 |
"
|
|
43 |
self new testUnwind1
|
|
44 |
"
|
|
45 |
!
|
|
46 |
|
|
47 |
downToNextSegmentThenUnwindAndDo:aBlock
|
249
|
48 |
self
|
|
49 |
downToSegment:(Processor activeProcess numberOfStackSegments + 1)
|
|
50 |
thenUnwindAndDo:aBlock
|
147
|
51 |
|
|
52 |
"
|
|
53 |
self new testUnwind2
|
|
54 |
"
|
|
55 |
!
|
|
56 |
|
|
57 |
downToSegment:nr thenDo:aBlock
|
|
58 |
Processor activeProcess numberOfStackSegments >= nr ifTrue:[
|
249
|
59 |
^ aBlock value
|
147
|
60 |
].
|
249
|
61 |
self
|
|
62 |
downToSegment:(Processor activeProcess numberOfStackSegments + 1)
|
|
63 |
thenDo:aBlock
|
147
|
64 |
|
|
65 |
"
|
|
66 |
self new testUnwind1
|
|
67 |
"
|
|
68 |
!
|
|
69 |
|
|
70 |
downToSegment:nr thenUnwindAndDo:aBlock
|
|
71 |
Processor activeProcess numberOfStackSegments >= nr ifTrue:[
|
249
|
72 |
aBlock home unwindThenDo: aBlock
|
147
|
73 |
].
|
249
|
74 |
self
|
|
75 |
downToSegment:(Processor activeProcess numberOfStackSegments + 1)
|
|
76 |
thenUnwindAndDo:aBlock
|
147
|
77 |
|
|
78 |
"
|
|
79 |
self new testUnwind2
|
|
80 |
"
|
|
81 |
!
|
|
82 |
|
249
|
83 |
exceptionObjectIs:ex
|
|
84 |
exceptionObject := ex
|
|
85 |
!
|
|
86 |
|
239
|
87 |
getAssocWithContext
|
|
88 |
^ self getSendersContext -> #foo
|
|
89 |
!
|
|
90 |
|
|
91 |
getSendersContext
|
|
92 |
^ thisContext sender
|
|
93 |
!
|
|
94 |
|
249
|
95 |
raiseNotification
|
|
96 |
NoHandlerError handle:[:ex |
|
|
97 |
ex return
|
|
98 |
] do:[
|
|
99 |
|t|
|
|
100 |
|
|
101 |
%{
|
|
102 |
extern void *__contextToDebug__;
|
|
103 |
__contextToDebug__ = (void *)__thisContext;
|
|
104 |
%}.
|
|
105 |
t := MyNotification raiseRequestFrom:self.
|
|
106 |
%{
|
|
107 |
extern void *__contextToDebug__;
|
|
108 |
__contextToDebug__ = (void *)__thisContext;
|
|
109 |
%}.
|
|
110 |
^ t
|
|
111 |
].
|
|
112 |
^ nil.
|
|
113 |
!
|
|
114 |
|
239
|
115 |
raiseWithContext
|
|
116 |
AbortOperationRequest raiseWith:self getSendersContext
|
240
|
117 |
!
|
|
118 |
|
|
119 |
selfReferringContext
|
|
120 |
|ref|
|
|
121 |
|
|
122 |
ref := thisContext.
|
|
123 |
^ thisContext
|
|
124 |
!
|
|
125 |
|
|
126 |
senderContext
|
|
127 |
^ thisContext sender
|
|
128 |
!
|
|
129 |
|
|
130 |
senderReferringContext1
|
|
131 |
^ self senderReferringContext:thisContext
|
|
132 |
!
|
|
133 |
|
|
134 |
senderReferringContext2
|
|
135 |
^ self senderContext
|
|
136 |
!
|
|
137 |
|
|
138 |
senderReferringContext:aContext
|
|
139 |
^ aContext
|
239
|
140 |
! !
|
|
141 |
|
|
142 |
!ContextTest2 methodsFor:'tests'!
|
|
143 |
|
|
144 |
testContextRef1
|
|
145 |
|assoc|
|
|
146 |
|
|
147 |
assoc := self getAssocWithContext.
|
|
148 |
ObjectMemory garbageCollect.
|
|
149 |
|
|
150 |
"
|
|
151 |
self new testContextRef1
|
|
152 |
"
|
|
153 |
!
|
|
154 |
|
|
155 |
testContextRef2
|
|
156 |
|
|
157 |
self getAssocWithContext.
|
|
158 |
ObjectMemory garbageCollect.
|
|
159 |
|
|
160 |
"
|
|
161 |
self new testContextRef2
|
|
162 |
"
|
|
163 |
!
|
|
164 |
|
|
165 |
testContextRef3
|
|
166 |
AbortOperationRequest handle:[:ex |
|
|
167 |
] do:[
|
249
|
168 |
self raiseWithContext.
|
239
|
169 |
].
|
|
170 |
ObjectMemory garbageCollect.
|
|
171 |
|
|
172 |
"
|
|
173 |
self new testContextRef3
|
|
174 |
"
|
|
175 |
!
|
|
176 |
|
|
177 |
testContextRef4
|
|
178 |
|con|
|
|
179 |
|
|
180 |
AbortOperationRequest handle:[:ex |
|
249
|
181 |
ObjectMemory garbageCollect.
|
|
182 |
con := ex parameter.
|
|
183 |
ObjectMemory garbageCollect.
|
239
|
184 |
] do:[
|
249
|
185 |
self raiseWithContext.
|
239
|
186 |
].
|
|
187 |
ObjectMemory garbageCollect.
|
|
188 |
|
|
189 |
"
|
|
190 |
self new testContextRef4
|
|
191 |
"
|
|
192 |
!
|
|
193 |
|
240
|
194 |
testContextRef5
|
|
195 |
self selfReferringContext.
|
|
196 |
ObjectMemory garbageCollect.
|
|
197 |
|
|
198 |
"
|
|
199 |
self new testContextRef5
|
|
200 |
"
|
|
201 |
!
|
|
202 |
|
|
203 |
testContextRef6
|
|
204 |
self senderReferringContext1.
|
|
205 |
ObjectMemory garbageCollect.
|
|
206 |
|
|
207 |
"
|
|
208 |
self new testContextRef6
|
|
209 |
"
|
|
210 |
!
|
|
211 |
|
|
212 |
testContextRef7
|
|
213 |
self senderReferringContext2.
|
|
214 |
ObjectMemory garbageCollect.
|
|
215 |
|
|
216 |
"
|
|
217 |
self new testContextRef7
|
|
218 |
"
|
|
219 |
!
|
|
220 |
|
249
|
221 |
testContextRef8
|
|
222 |
100000 timesRepeat:[
|
|
223 |
self raiseNotification.
|
|
224 |
self assert:(ObjectMemory spaceOf:exceptionObject suspendedContext) < 4.
|
|
225 |
].
|
|
226 |
|
|
227 |
"
|
|
228 |
self new testContextRef8
|
|
229 |
"
|
|
230 |
!
|
|
231 |
|
250
|
232 |
testContextRef9
|
|
233 |
|val|
|
|
234 |
|
|
235 |
val := self call1.
|
|
236 |
|
|
237 |
"
|
|
238 |
self new testContextRef9
|
|
239 |
"
|
|
240 |
!
|
|
241 |
|
100
|
242 |
testProcess1
|
101
|
243 |
|x set lockSet p arg|
|
|
244 |
|
|
245 |
lockSet := Semaphore forMutualExclusion.
|
|
246 |
set := Set new.
|
|
247 |
|
|
248 |
x := 1 @ 1.
|
|
249 |
|
|
250 |
arg := x.
|
|
251 |
|
|
252 |
p := [
|
249
|
253 |
[
|
|
254 |
lockSet critical:[set add:arg].
|
|
255 |
arg perform:#x .
|
|
256 |
] valueNowOrOnUnwindDo:[
|
|
257 |
lockSet critical:[set remove:arg].
|
|
258 |
].
|
101
|
259 |
] fork.
|
|
260 |
|
|
261 |
"
|
|
262 |
self new testProcess1
|
|
263 |
"
|
|
264 |
!
|
|
265 |
|
|
266 |
testProcess2
|
100
|
267 |
|x set lockSet p|
|
|
268 |
|
|
269 |
lockSet := Semaphore forMutualExclusion.
|
|
270 |
set := Set new.
|
|
271 |
|
|
272 |
x := 1 @ 1.
|
|
273 |
|
|
274 |
p := [:arg |
|
249
|
275 |
[
|
|
276 |
lockSet critical:[set add:arg].
|
|
277 |
arg perform:#x.
|
|
278 |
] valueNowOrOnUnwindDo:[
|
|
279 |
lockSet critical:[set remove:arg].
|
|
280 |
].
|
100
|
281 |
] forkWith:(Array with:x).
|
|
282 |
|
|
283 |
"
|
101
|
284 |
self new testProcess2
|
100
|
285 |
"
|
102
|
286 |
!
|
|
287 |
|
|
288 |
testProcess3
|
|
289 |
|x set lockSet p|
|
|
290 |
|
|
291 |
lockSet := Semaphore forMutualExclusion.
|
|
292 |
set := Set new.
|
|
293 |
|
|
294 |
x := 1 @ 1.
|
|
295 |
|
|
296 |
p := [:arg |
|
249
|
297 |
[
|
|
298 |
lockSet critical:[set add:arg].
|
|
299 |
arg perform:#x: with:1234.
|
|
300 |
] valueNowOrOnUnwindDo:[
|
|
301 |
lockSet critical:[set remove:arg].
|
|
302 |
].
|
102
|
303 |
] forkWith:(Array with:x).
|
|
304 |
|
|
305 |
"
|
|
306 |
self new testProcess3
|
|
307 |
"
|
147
|
308 |
!
|
|
309 |
|
|
310 |
testUnwind1
|
|
311 |
Transcript showCR:'1'.
|
|
312 |
self downToNextSegmentThenDo:[Transcript showCR:'2'. ^ self ].
|
|
313 |
Transcript showCR:'3'.
|
|
314 |
|
|
315 |
"
|
|
316 |
self new testUnwind1
|
|
317 |
"
|
|
318 |
!
|
|
319 |
|
|
320 |
testUnwind2
|
|
321 |
Transcript showCR:'1'.
|
|
322 |
self downToNextSegmentThenUnwindAndDo:[Transcript showCR:'2'. ^ self ].
|
|
323 |
Transcript showCR:'3'.
|
|
324 |
|
|
325 |
"
|
|
326 |
self new testUnwind2
|
|
327 |
"
|
|
328 |
!
|
|
329 |
|
|
330 |
testUnwind3
|
|
331 |
<context: #return>
|
|
332 |
|
|
333 |
|foo|
|
|
334 |
|
|
335 |
Transcript showCR:'1'.
|
|
336 |
self downToNextSegmentThenUnwindAndDo:[Transcript showCR:'2'. foo := #foo ].
|
|
337 |
Transcript showCR:'3'.
|
|
338 |
|
|
339 |
"
|
|
340 |
self new testUnwind3
|
|
341 |
"
|
|
342 |
!
|
|
343 |
|
|
344 |
testUnwind4
|
|
345 |
|foo|
|
|
346 |
|
|
347 |
Transcript showCR:'1'.
|
|
348 |
self downToNextSegmentThenDo:[Transcript showCR:'2'. foo := #foo ].
|
|
349 |
Transcript showCR:'3'.
|
|
350 |
|
|
351 |
"
|
|
352 |
self new testUnwind4
|
|
353 |
"
|
100
|
354 |
! !
|
|
355 |
|
249
|
356 |
!ContextTest2::MyNotification class methodsFor:'raising'!
|
|
357 |
|
|
358 |
raiseRequestFrom:someone
|
|
359 |
"raise a signal proceedable.
|
|
360 |
The argument, something is passed both as parameter and originator."
|
|
361 |
|
|
362 |
<context: #return>
|
|
363 |
|
|
364 |
|ex|
|
|
365 |
|
|
366 |
ex := self newExceptionFrom:someone.
|
|
367 |
someone exceptionObjectIs:ex.
|
|
368 |
^ (ex
|
|
369 |
suspendedContext:thisContext sender
|
|
370 |
parameter:someone)
|
|
371 |
raiseRequest.
|
|
372 |
! !
|
|
373 |
|
100
|
374 |
!ContextTest2 class methodsFor:'documentation'!
|
|
375 |
|
|
376 |
version
|
|
377 |
^ '$Header$'
|
|
378 |
! !
|