1447
|
1 |
"{ Package: 'stx:goodies/regression' }"
|
100
|
2 |
|
|
3 |
"{ NameSpace: RegressionTests }"
|
|
4 |
|
249
|
5 |
TestCase subclass:#ContextTest2
|
251
|
6 |
instanceVariableNames:'exceptionObject ttt'
|
249
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
1157
|
9 |
category:'tests-Regression-RuntimeSystem'
|
249
|
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 |
|
251
|
22 |
call10_1
|
|
23 |
|local|
|
|
24 |
|
|
25 |
^ self call10_2:[:x | local := x].
|
|
26 |
!
|
|
27 |
|
|
28 |
call10_2:aBlock
|
|
29 |
^ self call10_3:aBlock
|
250
|
30 |
!
|
|
31 |
|
251
|
32 |
call10_3:aBlock
|
252
|
33 |
aBlock value:thisContext.
|
|
34 |
^ thisContext sender sender
|
|
35 |
!
|
|
36 |
|
|
37 |
call11_1
|
|
38 |
|local|
|
|
39 |
|
|
40 |
self call11_2:[:x | local := x].
|
|
41 |
^ local value.
|
|
42 |
!
|
|
43 |
|
|
44 |
call11_2:aBlock
|
|
45 |
^ self call11_3:aBlock
|
|
46 |
!
|
|
47 |
|
|
48 |
call11_3:aBlock
|
|
49 |
aBlock value:[thisContext].
|
|
50 |
^ thisContext sender sender
|
250
|
51 |
!
|
|
52 |
|
251
|
53 |
call9_1
|
|
54 |
^ self call9_2
|
|
55 |
!
|
250
|
56 |
|
251
|
57 |
call9_2
|
|
58 |
^ self call9_3
|
|
59 |
!
|
|
60 |
|
|
61 |
call9_3
|
250
|
62 |
ttt := thisContext.
|
|
63 |
^ ttt sender sender
|
|
64 |
!
|
|
65 |
|
654
|
66 |
callRecursive: level withArg:argument thenDo:aBlock
|
|
67 |
level == 0 ifTrue:[
|
1447
|
68 |
aBlock value:thisContext.
|
|
69 |
^ self.
|
654
|
70 |
].
|
|
71 |
self callRecursive:level-1 withArg:argument thenDo:aBlock
|
|
72 |
|
|
73 |
"Created: / 07-03-2012 / 13:04:48 / cg"
|
|
74 |
!
|
|
75 |
|
147
|
76 |
downToNextSegmentThenDo:aBlock
|
249
|
77 |
self
|
|
78 |
downToSegment:(Processor activeProcess numberOfStackSegments + 1)
|
|
79 |
thenDo:aBlock
|
147
|
80 |
|
|
81 |
"
|
|
82 |
self new testUnwind1
|
|
83 |
"
|
|
84 |
!
|
|
85 |
|
|
86 |
downToNextSegmentThenUnwindAndDo:aBlock
|
249
|
87 |
self
|
|
88 |
downToSegment:(Processor activeProcess numberOfStackSegments + 1)
|
|
89 |
thenUnwindAndDo:aBlock
|
147
|
90 |
|
|
91 |
"
|
|
92 |
self new testUnwind2
|
|
93 |
"
|
|
94 |
!
|
|
95 |
|
|
96 |
downToSegment:nr thenDo:aBlock
|
|
97 |
Processor activeProcess numberOfStackSegments >= nr ifTrue:[
|
249
|
98 |
^ aBlock value
|
147
|
99 |
].
|
249
|
100 |
self
|
|
101 |
downToSegment:(Processor activeProcess numberOfStackSegments + 1)
|
|
102 |
thenDo:aBlock
|
147
|
103 |
|
|
104 |
"
|
|
105 |
self new testUnwind1
|
|
106 |
"
|
|
107 |
!
|
|
108 |
|
|
109 |
downToSegment:nr thenUnwindAndDo:aBlock
|
|
110 |
Processor activeProcess numberOfStackSegments >= nr ifTrue:[
|
249
|
111 |
aBlock home unwindThenDo: aBlock
|
147
|
112 |
].
|
249
|
113 |
self
|
|
114 |
downToSegment:(Processor activeProcess numberOfStackSegments + 1)
|
|
115 |
thenUnwindAndDo:aBlock
|
147
|
116 |
|
|
117 |
"
|
|
118 |
self new testUnwind2
|
|
119 |
"
|
|
120 |
!
|
|
121 |
|
249
|
122 |
exceptionObjectIs:ex
|
|
123 |
exceptionObject := ex
|
|
124 |
!
|
|
125 |
|
239
|
126 |
getAssocWithContext
|
|
127 |
^ self getSendersContext -> #foo
|
|
128 |
!
|
|
129 |
|
|
130 |
getSendersContext
|
|
131 |
^ thisContext sender
|
|
132 |
!
|
|
133 |
|
249
|
134 |
raiseNotification
|
|
135 |
NoHandlerError handle:[:ex |
|
1447
|
136 |
ex return
|
249
|
137 |
] do:[
|
1447
|
138 |
|t|
|
249
|
139 |
|
|
140 |
%{
|
|
141 |
extern void *__contextToDebug__;
|
|
142 |
__contextToDebug__ = (void *)__thisContext;
|
|
143 |
%}.
|
1447
|
144 |
t := MyNotification raiseRequestFrom:self.
|
249
|
145 |
%{
|
|
146 |
extern void *__contextToDebug__;
|
|
147 |
__contextToDebug__ = (void *)__thisContext;
|
|
148 |
%}.
|
1447
|
149 |
^ t
|
249
|
150 |
].
|
|
151 |
^ nil.
|
|
152 |
!
|
|
153 |
|
239
|
154 |
raiseWithContext
|
|
155 |
AbortOperationRequest raiseWith:self getSendersContext
|
240
|
156 |
!
|
|
157 |
|
|
158 |
selfReferringContext
|
|
159 |
|ref|
|
|
160 |
|
|
161 |
ref := thisContext.
|
|
162 |
^ thisContext
|
|
163 |
!
|
|
164 |
|
|
165 |
senderContext
|
|
166 |
^ thisContext sender
|
|
167 |
!
|
|
168 |
|
|
169 |
senderReferringContext1
|
|
170 |
^ self senderReferringContext:thisContext
|
|
171 |
!
|
|
172 |
|
|
173 |
senderReferringContext2
|
|
174 |
^ self senderContext
|
|
175 |
!
|
|
176 |
|
|
177 |
senderReferringContext:aContext
|
|
178 |
^ aContext
|
239
|
179 |
! !
|
|
180 |
|
|
181 |
!ContextTest2 methodsFor:'tests'!
|
|
182 |
|
|
183 |
testContextRef1
|
|
184 |
|assoc|
|
|
185 |
|
|
186 |
assoc := self getAssocWithContext.
|
|
187 |
ObjectMemory garbageCollect.
|
|
188 |
|
|
189 |
"
|
|
190 |
self new testContextRef1
|
|
191 |
"
|
|
192 |
!
|
|
193 |
|
251
|
194 |
testContextRef10
|
|
195 |
|val|
|
|
196 |
|
|
197 |
val := self call10_1.
|
|
198 |
ObjectMemory dumpObject:val.
|
252
|
199 |
ObjectMemory dumpObject:(val varAt:1).
|
|
200 |
ObjectMemory dumpObject:((val varAt:1) varAt:1).
|
251
|
201 |
|
|
202 |
"
|
252
|
203 |
self new testContextRef10
|
|
204 |
"
|
|
205 |
!
|
|
206 |
|
|
207 |
testContextRef11
|
|
208 |
|val|
|
|
209 |
|
|
210 |
val := self call10_1.
|
|
211 |
ObjectMemory dumpObject:val.
|
|
212 |
|
|
213 |
"
|
|
214 |
self new testContextRef11
|
251
|
215 |
"
|
|
216 |
!
|
|
217 |
|
239
|
218 |
testContextRef2
|
|
219 |
|
|
220 |
self getAssocWithContext.
|
|
221 |
ObjectMemory garbageCollect.
|
|
222 |
|
|
223 |
"
|
|
224 |
self new testContextRef2
|
|
225 |
"
|
|
226 |
!
|
|
227 |
|
|
228 |
testContextRef3
|
|
229 |
AbortOperationRequest handle:[:ex |
|
|
230 |
] do:[
|
249
|
231 |
self raiseWithContext.
|
239
|
232 |
].
|
|
233 |
ObjectMemory garbageCollect.
|
|
234 |
|
|
235 |
"
|
|
236 |
self new testContextRef3
|
|
237 |
"
|
|
238 |
!
|
|
239 |
|
|
240 |
testContextRef4
|
|
241 |
|con|
|
|
242 |
|
|
243 |
AbortOperationRequest handle:[:ex |
|
249
|
244 |
ObjectMemory garbageCollect.
|
|
245 |
con := ex parameter.
|
|
246 |
ObjectMemory garbageCollect.
|
239
|
247 |
] do:[
|
249
|
248 |
self raiseWithContext.
|
239
|
249 |
].
|
|
250 |
ObjectMemory garbageCollect.
|
|
251 |
|
|
252 |
"
|
|
253 |
self new testContextRef4
|
|
254 |
"
|
|
255 |
!
|
|
256 |
|
240
|
257 |
testContextRef5
|
|
258 |
self selfReferringContext.
|
|
259 |
ObjectMemory garbageCollect.
|
|
260 |
|
|
261 |
"
|
|
262 |
self new testContextRef5
|
|
263 |
"
|
|
264 |
!
|
|
265 |
|
|
266 |
testContextRef6
|
|
267 |
self senderReferringContext1.
|
|
268 |
ObjectMemory garbageCollect.
|
|
269 |
|
|
270 |
"
|
|
271 |
self new testContextRef6
|
|
272 |
"
|
|
273 |
!
|
|
274 |
|
|
275 |
testContextRef7
|
|
276 |
self senderReferringContext2.
|
|
277 |
ObjectMemory garbageCollect.
|
|
278 |
|
|
279 |
"
|
|
280 |
self new testContextRef7
|
|
281 |
"
|
|
282 |
!
|
|
283 |
|
249
|
284 |
testContextRef8
|
|
285 |
100000 timesRepeat:[
|
1447
|
286 |
self raiseNotification.
|
|
287 |
self assert:(ObjectMemory spaceOf:exceptionObject suspendedContext) < 4.
|
249
|
288 |
].
|
|
289 |
|
|
290 |
"
|
|
291 |
self new testContextRef8
|
|
292 |
"
|
|
293 |
!
|
|
294 |
|
250
|
295 |
testContextRef9
|
|
296 |
|val|
|
|
297 |
|
251
|
298 |
val := self call9_1.
|
|
299 |
ObjectMemory dumpObject:val.
|
|
300 |
ObjectMemory dumpObject:ttt.
|
250
|
301 |
|
|
302 |
"
|
|
303 |
self new testContextRef9
|
|
304 |
"
|
|
305 |
!
|
|
306 |
|
654
|
307 |
testDisplayString1
|
|
308 |
"the generated displayString must be a string (even if one of the args or receiver
|
|
309 |
is a Twobytestring"
|
|
310 |
|
|
311 |
Transcript showCR:'1'.
|
1447
|
312 |
self
|
|
313 |
callRecursive:3
|
|
314 |
withArg:((Unicode16String new:2)
|
|
315 |
at:1 put:(Character value:16r151);
|
|
316 |
at:2 put:(Character value:16rFF00);
|
|
317 |
yourself)
|
|
318 |
thenDo:[:context |
|
|
319 |
self assert:(context displayString bitsPerCharacter == 8).
|
|
320 |
self assert:(context fullPrintString bitsPerCharacter == 8).
|
|
321 |
].
|
654
|
322 |
|
|
323 |
"
|
|
324 |
self new testDisplayString1
|
|
325 |
"
|
|
326 |
|
|
327 |
"Created: / 07-03-2012 / 13:03:32 / cg"
|
|
328 |
!
|
|
329 |
|
100
|
330 |
testProcess1
|
101
|
331 |
|x set lockSet p arg|
|
|
332 |
|
|
333 |
lockSet := Semaphore forMutualExclusion.
|
|
334 |
set := Set new.
|
|
335 |
|
|
336 |
x := 1 @ 1.
|
|
337 |
|
|
338 |
arg := x.
|
|
339 |
|
|
340 |
p := [
|
1447
|
341 |
[
|
|
342 |
lockSet critical:[set add:arg].
|
|
343 |
arg perform:#x .
|
|
344 |
] ensure:[
|
|
345 |
lockSet critical:[set remove:arg].
|
|
346 |
].
|
101
|
347 |
] fork.
|
|
348 |
|
|
349 |
"
|
|
350 |
self new testProcess1
|
|
351 |
"
|
|
352 |
!
|
|
353 |
|
|
354 |
testProcess2
|
100
|
355 |
|x set lockSet p|
|
|
356 |
|
|
357 |
lockSet := Semaphore forMutualExclusion.
|
|
358 |
set := Set new.
|
|
359 |
|
|
360 |
x := 1 @ 1.
|
|
361 |
|
|
362 |
p := [:arg |
|
1447
|
363 |
[
|
|
364 |
lockSet critical:[set add:arg].
|
|
365 |
arg perform:#x.
|
|
366 |
] ensure:[
|
|
367 |
lockSet critical:[set remove:arg].
|
|
368 |
].
|
100
|
369 |
] forkWith:(Array with:x).
|
|
370 |
|
|
371 |
"
|
101
|
372 |
self new testProcess2
|
100
|
373 |
"
|
102
|
374 |
!
|
|
375 |
|
|
376 |
testProcess3
|
|
377 |
|x set lockSet p|
|
|
378 |
|
|
379 |
lockSet := Semaphore forMutualExclusion.
|
|
380 |
set := Set new.
|
|
381 |
|
|
382 |
x := 1 @ 1.
|
|
383 |
|
|
384 |
p := [:arg |
|
1447
|
385 |
[
|
|
386 |
lockSet critical:[set add:arg].
|
|
387 |
arg perform:#x: with:1234.
|
|
388 |
lockSet critical:[set rehash].
|
|
389 |
] ensure:[
|
|
390 |
lockSet critical:[set remove:arg].
|
|
391 |
].
|
102
|
392 |
] forkWith:(Array with:x).
|
|
393 |
|
|
394 |
"
|
|
395 |
self new testProcess3
|
|
396 |
"
|
147
|
397 |
!
|
|
398 |
|
|
399 |
testUnwind1
|
|
400 |
Transcript showCR:'1'.
|
|
401 |
self downToNextSegmentThenDo:[Transcript showCR:'2'. ^ self ].
|
|
402 |
Transcript showCR:'3'.
|
|
403 |
|
|
404 |
"
|
|
405 |
self new testUnwind1
|
|
406 |
"
|
|
407 |
!
|
|
408 |
|
|
409 |
testUnwind2
|
|
410 |
Transcript showCR:'1'.
|
|
411 |
self downToNextSegmentThenUnwindAndDo:[Transcript showCR:'2'. ^ self ].
|
|
412 |
Transcript showCR:'3'.
|
|
413 |
|
|
414 |
"
|
|
415 |
self new testUnwind2
|
|
416 |
"
|
|
417 |
!
|
|
418 |
|
|
419 |
testUnwind3
|
|
420 |
<context: #return>
|
|
421 |
|
|
422 |
|foo|
|
|
423 |
|
|
424 |
Transcript showCR:'1'.
|
|
425 |
self downToNextSegmentThenUnwindAndDo:[Transcript showCR:'2'. foo := #foo ].
|
|
426 |
Transcript showCR:'3'.
|
|
427 |
|
|
428 |
"
|
|
429 |
self new testUnwind3
|
|
430 |
"
|
|
431 |
!
|
|
432 |
|
|
433 |
testUnwind4
|
|
434 |
|foo|
|
|
435 |
|
|
436 |
Transcript showCR:'1'.
|
|
437 |
self downToNextSegmentThenDo:[Transcript showCR:'2'. foo := #foo ].
|
|
438 |
Transcript showCR:'3'.
|
|
439 |
|
|
440 |
"
|
|
441 |
self new testUnwind4
|
|
442 |
"
|
100
|
443 |
! !
|
|
444 |
|
249
|
445 |
!ContextTest2::MyNotification class methodsFor:'raising'!
|
|
446 |
|
|
447 |
raiseRequestFrom:someone
|
|
448 |
"raise a signal proceedable.
|
|
449 |
The argument, something is passed both as parameter and originator."
|
|
450 |
|
|
451 |
<context: #return>
|
|
452 |
|
|
453 |
|ex|
|
|
454 |
|
669
|
455 |
ex := self newException.
|
249
|
456 |
someone exceptionObjectIs:ex.
|
|
457 |
^ (ex
|
1447
|
458 |
suspendedContext:thisContext sender
|
|
459 |
parameter:someone originator:someone)
|
|
460 |
raiseRequest.
|
249
|
461 |
! !
|
|
462 |
|
100
|
463 |
!ContextTest2 class methodsFor:'documentation'!
|
|
464 |
|
|
465 |
version
|
|
466 |
^ '$Header$'
|
|
467 |
! !
|
1157
|
468 |
|