/
SourceFileArrayTest.class.st
415 lines (342 loc) · 16.1 KB
/
SourceFileArrayTest.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
"
This test documents the source pointer address conversion methods for ExpandedSourceFileArray.
The available address space for source pointers in a traditional CompiledMethod is 16r1000000 through 16r4FFFFFF. StandardSourceFileArray maps positions in the sources file to address range 16r1000000 through 16r1FFFFFF and 16r3000000 through 16r3FFFFFF, and positions in the changes file to address range 16r2000000 through 16r2FFFFFF and 16r4000000 through 16r4FFFFFF. This permits a maximum file size of 16r2000000 (32MB) for both the sources file and the changes file.
ExpandedSourceFileArray extends the source pointer address space using bit 25 of the source pointer to identify the external sources and changes files, with the remaining high order bits treated as address extension. This limits the number of external file references to two (the traditional sources and changes files). If additional external file references are needed in the future, some higher order bits in the source pointer address space should be allocated for that purpose.
The use of bit 25 of the source pointer for file references permits backward compatibility with StandardSourceFileArray, with essentially unlimited address space expansion for the sources and changes files.
"
Class {
#name : #SourceFileArrayTest,
#superclass : #TestCase,
#category : #'Tests-Files'
}
{ #category : #running }
SourceFileArrayTest >> ensureChangesFileOpenedInProcess [
"Ensure the changes file is open"
| remoteString |
remoteString := SourceFiles remoteStringAt: thisContext method sourcePointer.
self deny: remoteString string isNil.
"self deny: ProcessAndSessionLocalSourcesFileArray value isNil."
]
{ #category : #testing }
SourceFileArrayTest >> testAddressRange [
"Test source pointer to file position address translation across a wide address range"
| sf i p a |
sf := SourceFileArray new.
16r1000000 to: 16r10000000 by: 4093 do: [:e |
i := sf fileIndexFromSourcePointer: e.
p := sf filePositionFromSourcePointer: e.
a := sf sourcePointerFromFileIndex: i andPosition: p.
self assert: a = e]
]
{ #category : #testing }
SourceFileArrayTest >> testChangesFileAddressRange [
"Test file position to source pointer address translation for the changes file"
| sf i p a a2 |
sf := SourceFileArray new.
0 to: 16r1FFFFFFF by: 4093 do: [:e |
a := sf sourcePointerFromFileIndex: 2 andPosition: e.
i := sf fileIndexFromSourcePointer: a.
self assert: i = 2.
p := sf filePositionFromSourcePointer: a.
self assert: p = e.
a2 := sf sourcePointerFromFileIndex: 2 andPosition: p.
self assert: a2 = a].
0 to: 16rFFFFFF by: 811 do: [:e |
a := sf sourcePointerFromFileIndex: 2 andPosition: e.
self assert: (a between: 16r2000000 and: 16r2FFFFFF)].
16r1000000 to: 16r1FFFFFF by: 811 do: [:e |
a := sf sourcePointerFromFileIndex: 2 andPosition: e.
self assert: (a between: 16r4000000 and: 16r4FFFFFF)].
16r2000000 to: 16r2FFFFFF by: 811 do: [:e |
a := sf sourcePointerFromFileIndex: 2 andPosition: e.
self assert: (a between: 16r6000000 and: 16r6FFFFFF)].
16r3000000 to: 16r3FFFFFF by: 811 do: [:e |
a := sf sourcePointerFromFileIndex: 2 andPosition: e.
self assert: (a between: 16r8000000 and: 16r8FFFFFF)].
16r4000000 to: 16r4FFFFFF by: 811 do: [:e |
a := sf sourcePointerFromFileIndex: 2 andPosition: e.
self assert: (a between: 16rA000000 and: 16rAFFFFFF)].
16r5000000 to: 16r5FFFFFF by: 811 do: [:e |
a := sf sourcePointerFromFileIndex: 2 andPosition: e.
self assert: (a between: 16rC000000 and: 16rCFFFFFF)].
16r6000000 to: 16r6FFFFFF by: 811 do: [:e |
a := sf sourcePointerFromFileIndex: 2 andPosition: e.
self assert: (a between: 16rE000000 and: 16rEFFFFFF)].
16r7000000 to: 16r7FFFFFF by: 811 do: [:e |
a := sf sourcePointerFromFileIndex: 2 andPosition: e.
self assert: (a between: 16r10000000 and: 16r10FFFFFF)]
]
{ #category : #testing }
SourceFileArrayTest >> testChangesFileStream [
self assert: SourceFiles changesFileStream isNotNil
]
{ #category : #testing }
SourceFileArrayTest >> testFileIndexFromSourcePointer [
"Test derivation of file index for sources or changes file from source pointers"
| sf |
sf := SourceFileArray new.
"sources file mapping"
self assert: 1 = (sf fileIndexFromSourcePointer: 16r1000000).
self assert: 1 = (sf fileIndexFromSourcePointer: 16r1000013).
self assert: 1 = (sf fileIndexFromSourcePointer: 16r1FFFFFF).
self assert: 1 = (sf fileIndexFromSourcePointer: 16r3000000).
self assert: 1 = (sf fileIndexFromSourcePointer: 16r3000013).
self assert: 1 = (sf fileIndexFromSourcePointer: 16r3FFFFFF).
self assert: 1 = (sf fileIndexFromSourcePointer: 16r5000000).
self assert: 1 = (sf fileIndexFromSourcePointer: 16r5000013).
self assert: 1 = (sf fileIndexFromSourcePointer: 16r5FFFFFF).
(16r1000000 to: 16r1FFFFFF by: 811) do: [:e | self assert: 1 = (sf fileIndexFromSourcePointer: e)].
(16r3000000 to: 16r3FFFFFF by: 811) do: [:e | self assert: 1 = (sf fileIndexFromSourcePointer: e)].
"changes file mapping"
self assert: 2 = (sf fileIndexFromSourcePointer: 16r2000000).
self assert: 2 = (sf fileIndexFromSourcePointer: 16r2000013).
self assert: 2 = (sf fileIndexFromSourcePointer: 16r2FFFFFF).
self assert: 2 = (sf fileIndexFromSourcePointer: 16r4000000).
self assert: 2 = (sf fileIndexFromSourcePointer: 16r4000013).
self assert: 2 = (sf fileIndexFromSourcePointer: 16r4FFFFFF).
self assert: 2 = (sf fileIndexFromSourcePointer: 16r6000000).
self assert: 2 = (sf fileIndexFromSourcePointer: 16r6000013).
self assert: 2 = (sf fileIndexFromSourcePointer: 16r6FFFFFF).
(16r2000000 to: 16r2FFFFFF by: 811) do: [:e | self assert: 2 = (sf fileIndexFromSourcePointer: e)].
(16r4000000 to: 16r4FFFFFF by: 811) do: [:e | self assert: 2 = (sf fileIndexFromSourcePointer: e)].
"the following numeric ranges are unused but currently produces results as follows"
self assert: 0 = (sf fileIndexFromSourcePointer: 16r0000000).
self assert: 0 = (sf fileIndexFromSourcePointer: 16r0000013).
self assert: 0 = (sf fileIndexFromSourcePointer: 16r0FFFFFF)
]
{ #category : #testing }
SourceFileArrayTest >> testFilePositionFromSourcePointer [
"Test derivation of file position for sources or changes file from source pointers"
| sf |
sf := SourceFileArray new.
"sources file"
self assert: 0 = (sf filePositionFromSourcePointer: 16r1000000).
self assert: 16r13 = (sf filePositionFromSourcePointer: 16r1000013).
self assert: 16rFFFFFF = (sf filePositionFromSourcePointer: 16r1FFFFFF).
self assert: 16r1000000 = (sf filePositionFromSourcePointer: 16r3000000).
self assert: 16r1000013 = (sf filePositionFromSourcePointer: 16r3000013).
self assert: 16r1FFFFFF = (sf filePositionFromSourcePointer: 16r3FFFFFF).
"changes file"
self assert: 0 = (sf filePositionFromSourcePointer: 16r2000000).
self assert: 16r13 = (sf filePositionFromSourcePointer: 16r2000013).
self assert: 16rFFFFFF = (sf filePositionFromSourcePointer: 16r2FFFFFF).
self assert: 16r1000000 = (sf filePositionFromSourcePointer: 16r4000000).
self assert: 16r1000013 = (sf filePositionFromSourcePointer: 16r4000013).
self assert: 16r1FFFFFF = (sf filePositionFromSourcePointer: 16r4FFFFFF).
"the following numeric ranges are unused but currently produces results as follows"
self assert: 0 = (sf filePositionFromSourcePointer: 16r0000000).
self assert: 16r13 = (sf filePositionFromSourcePointer: 16r0000013).
self assert: 16rFFFFFF = (sf filePositionFromSourcePointer: 16r0FFFFFF)
]
{ #category : #testing }
SourceFileArrayTest >> testForkedRead [
| originalString remoteString readSemaphore readString testSemaphore |
originalString := '"test"'.
remoteString := nil.
readSemaphore := Semaphore new.
testSemaphore := Semaphore new.
self ensureChangesFileOpenedInProcess.
[ self ensureChangesFileOpenedInProcess.
readSemaphore wait.
"Read the string that was written in other process."
readString := remoteString string.
testSemaphore signal
] fork.
"Write the string, that will be read in other process."
remoteString := SourceFiles remoteStringForNewString: originalString.
readSemaphore signal.
testSemaphore wait.
self assert: readString equals: originalString.
]
{ #category : #testing }
SourceFileArrayTest >> testForkedWrite [
| originalString remoteString readSemaphore readString testSemaphore |
originalString := '"test"'.
remoteString := nil.
readSemaphore := Semaphore new.
testSemaphore := Semaphore new.
self ensureChangesFileOpenedInProcess.
[ self ensureChangesFileOpenedInProcess.
readSemaphore wait.
"Write the string, that will be read in other process."
remoteString := SourceFiles remoteStringForNewString: originalString.
testSemaphore signal
] fork.
readSemaphore signal.
testSemaphore wait.
"Read the string that was written in other process."
readString := remoteString string.
self assert: readString equals: originalString.
]
{ #category : #testing }
SourceFileArrayTest >> testProtocol [
"Test that we can access protocol correctly"
| okCm notOkCm |
okCm := Point>>#dotProduct: .
self assert: (((SourceFiles sourcedDataAt: okCm sourcePointer)) beginsWith:
'Point methodsFor: ''point functions''').
self assert: (SourceFiles protocolAt: okCm sourcePointer) = 'point functions'.
notOkCm := Behavior >> #superclass.
self assert: (SourceFiles protocolAt: notOkCm sourcePointer) = 'accessing class hierarchy'.
]
{ #category : #testing }
SourceFileArrayTest >> testRemoteStringReadsInGivenSourceFileArray [
| fs array remoteString readStream |
fs := FileSystem memory.
array := SourceFileArray new.
array changesFileStream: (SourceFile on: 'changes.chunk' potentialLocations: {fs root}) tryOpen.
array sourcesFileStream: (SourceFile on: 'sources.chunk' potentialLocations: {fs root}) tryOpen.
remoteString := array remoteStringForNewString: 'test'.
self assert: remoteString string equals: 'test'.
self assert: (array fileAt: remoteString sourceFileNumber) equals: array changesFileStream.
readStream := (fs / 'changes.chunk') readStream.
readStream position: remoteString position.
self assert: (ChunkReadStream on: readStream) next equals: 'test'
]
{ #category : #testing }
SourceFileArrayTest >> testRemoteStringWritesInGivenSourceFileArray [
| fs array |
fs := FileSystem memory.
array := SourceFileArray new.
array
changesFileStream: (SourceFile on: 'changes.chunk' potentialLocations: {fs root}) tryOpen.
array
sourcesFileStream: (SourceFile on: 'sources.chunk' potentialLocations: {fs root}) tryOpen.
array remoteStringForNewString: 'test'.
self
assert: (fs / 'changes.chunk') contents
equals:
'
test!'
]
{ #category : #testing }
SourceFileArrayTest >> testSourcePointerFromFileIndexAndPosition [
"Test valid input ranges"
| sf |
sf := SourceFileArray new.
self should: [ sf sourcePointerFromFileIndex: 0 andPosition: 0 ] raise: Error.
sf sourcePointerFromFileIndex: 1 andPosition: 0.
sf sourcePointerFromFileIndex: 2 andPosition: 0.
self should: [ sf sourcePointerFromFileIndex: 0 andPosition: 3 ] raise: Error.
self should: [ sf sourcePointerFromFileIndex: 1 andPosition: -1 ] raise: Error.
sf sourcePointerFromFileIndex: 1 andPosition: 16r1FFFFFF.
sf sourcePointerFromFileIndex: 1 andPosition: 16r2000000.
self should: [ sf sourcePointerFromFileIndex: 3 andPosition: 0 ] raise: Error.
self should: [ sf sourcePointerFromFileIndex: 4 andPosition: 0 ] raise: Error.
self assert: 16r1000000 = (sf sourcePointerFromFileIndex: 1 andPosition: 0).
self assert: 16r1000013 = (sf sourcePointerFromFileIndex: 1 andPosition: 16r13).
self assert: 16r1FFFFFF = (sf sourcePointerFromFileIndex: 1 andPosition: 16rFFFFFF).
self assert: 16r2000000 = (sf sourcePointerFromFileIndex: 2 andPosition: 0).
self assert: 16r2000013 = (sf sourcePointerFromFileIndex: 2 andPosition: 16r13).
self assert: 16r2FFFFFF = (sf sourcePointerFromFileIndex: 2 andPosition: 16rFFFFFF).
self assert: 16r3000000 = (sf sourcePointerFromFileIndex: 1 andPosition: 16r1000000).
self assert: 16r3000013 = (sf sourcePointerFromFileIndex: 1 andPosition: 16r1000013).
self assert: 16r3FFFFFF = (sf sourcePointerFromFileIndex: 1 andPosition: 16r1FFFFFF).
self assert: 16r4000000 = (sf sourcePointerFromFileIndex: 2 andPosition: 16r1000000).
self assert: 16r4000013 = (sf sourcePointerFromFileIndex: 2 andPosition: 16r1000013).
self assert: 16r4FFFFFF = (sf sourcePointerFromFileIndex: 2 andPosition: 16r1FFFFFF)
]
{ #category : #testing }
SourceFileArrayTest >> testSourcesFileAddressRange [
"Test file position to source pointer address translation for the sources file"
| sf i p a a2 |
sf := SourceFileArray new.
0 to: 16r1FFFFFFF by: 4093 do: [:e |
a := sf sourcePointerFromFileIndex: 1 andPosition: e.
i := sf fileIndexFromSourcePointer: a.
self assert: i = 1.
p := sf filePositionFromSourcePointer: a.
self assert: p = e.
a2 := sf sourcePointerFromFileIndex: 1 andPosition: p.
self assert: a2 = a].
0 to: 16rFFFFFF by: 811 do: [:e |
a := sf sourcePointerFromFileIndex: 1 andPosition: e.
self assert: (a between: 16r1000000 and: 16r1FFFFFF)].
16r1000000 to: 16r1FFFFFF by: 811 do: [:e |
a := sf sourcePointerFromFileIndex: 1 andPosition: e.
self assert: (a between: 16r3000000 and: 16r3FFFFFF)].
16r2000000 to: 16r2FFFFFF by: 811 do: [:e |
a := sf sourcePointerFromFileIndex: 1 andPosition: e.
self assert: (a between: 16r5000000 and: 16r5FFFFFF)].
16r3000000 to: 16r3FFFFFF by: 811 do: [:e |
a := sf sourcePointerFromFileIndex: 1 andPosition: e.
self assert: (a between: 16r7000000 and: 16r7FFFFFF)].
16r4000000 to: 16r4FFFFFF by: 811 do: [:e |
a := sf sourcePointerFromFileIndex: 1 andPosition: e.
self assert: (a between: 16r9000000 and: 16r9FFFFFF)].
16r5000000 to: 16r5FFFFFF by: 811 do: [:e |
a := sf sourcePointerFromFileIndex: 1 andPosition: e.
self assert: (a between: 16rB000000 and: 16rBFFFFFF)].
16r6000000 to: 16r6FFFFFF by: 811 do: [:e |
a := sf sourcePointerFromFileIndex: 1 andPosition: e.
self assert: (a between: 16rD000000 and: 16rDFFFFFF)].
16r7000000 to: 16r7FFFFFF by: 811 do: [:e |
a := sf sourcePointerFromFileIndex: 1 andPosition: e.
self assert: (a between: 16rF000000 and: 16rFFFFFFF)]
]
{ #category : #testing }
SourceFileArrayTest >> testSourcesFileStream [
self assert: SourceFiles sourcesFileStream isNotNil
]
{ #category : #testing }
SourceFileArrayTest >> testTimeStamp [
"Test that we can access timeStamp correctly"
| okCm |
okCm := Point>>#dotProduct: .
self assert: (((SourceFiles sourcedDataAt: okCm sourcePointer)) beginsWith:
'Point methodsFor: ''point functions'' stamp: ''''').
]
{ #category : #testing }
SourceFileArrayTest >> testWriteSourceWritesInGivenSourceFileArray [
| fs array |
fs := FileSystem memory.
array := SourceFileArray new.
array
changesFileStream: (SourceFile on: 'changes.chunk' potentialLocations: {fs root}) tryOpen.
array
sourcesFileStream: (SourceFile on: 'sources.chunk' potentialLocations: {fs root}) tryOpen.
array
writeSource: 'some source'
preamble: 'some preamble'
onSuccess: [ :sourcePointer | "continue with assertions" ]
onFail: [ "fail the test" self fail ].
self assert: (fs / 'changes.chunk') contents equals: 'some preamblesome source!'
]
{ #category : #testing }
SourceFileArrayTest >> testWriteToBufferedStream [
| fs array |
fs := FileSystem memory.
array := SourceFileArray new.
array changesFileStream:
(ZnCharacterReadWriteStream on: (ZnBufferedReadWriteStream on: (fs binaryWriteStreamOn: (fs / 'changes.chunk') path)) encoding: #utf8).
array sourcesFileStream:
(ZnCharacterReadWriteStream on: (ZnBufferedReadWriteStream on: (fs binaryWriteStreamOn: (fs / 'sources.chunk') path)) encoding: #utf8).
array
writeSource: 'some source'
preamble: 'some preamble'
onSuccess: [ :sourcePointer | "continue with assertions" ]
onFail: [ "fail the test" self fail ].
self assert: (fs / 'changes.chunk') contents equals: 'some preamblesome source!'
]
{ #category : #testing }
SourceFileArrayTest >> testWriteToChangesFileInGivenSourceFileArray [
| fs array |
fs := FileSystem memory.
array := SourceFileArray new.
array
changesFileStream: (SourceFile on: 'changes.chunk' potentialLocations: {fs root}) tryOpen.
array
sourcesFileStream: (SourceFile on: 'sources.chunk' potentialLocations: {fs root}) tryOpen.
array
changesWriteStreamDo: [ :changesFile |
changesFile
cr;
cr;
nextChunkPut: 'test';
cr ].
self
assert: (fs / 'changes.chunk') contents
equals:
'
test!'
]