]> gitweb.factorcode.org Git - factor.git/blob - extra/tools/image-analyzer/gc-info/gc-info-tests.factor
compiler.*: fix the tests that broke because i removed the stack-frame variable
[factor.git] / extra / tools / image-analyzer / gc-info / gc-info-tests.factor
1 USING: accessors alien.c-types alien.syntax arrays assocs bit-arrays
2 classes.struct combinators combinators.short-circuit compiler
3 compiler.cfg.debugger compiler.cfg.instructions compiler.cfg.linearization
4 compiler.cfg.stack-frame compiler.codegen.gc-maps compiler.units fry generic
5 grouping io io.encodings.binary io.streams.byte-array kernel math namespaces
6 random sequences sequences.generalizations
7 tools.image-analyzer.gc-info tools.image-analyzer.utils tools.test vm
8 vocabs words ;
9 IN: tools.image-analyzer.gc-info.tests
10 QUALIFIED: cpu.x86.features.private
11 QUALIFIED: crypto.aes.utils
12 QUALIFIED: effects
13 QUALIFIED: gml.coremath
14 QUALIFIED: opencl
15
16 : normal? ( word -- ? )
17     { [ generic? ] [ primitive? ] [ inline? ] [ no-compile? ] } 1|| not ;
18
19 : word>gc-info ( word -- gc-info )
20     word>byte-array binary <byte-reader> <backwards-reader> [
21         gc-info read-struct-safe
22     ] with-input-stream ;
23
24 : cfg>gc-maps ( cfg -- gc-maps )
25     cfg>insns [ gc-map-insn? ] filter [ gc-map>> ] map
26     [ gc-map-needed? ] filter ;
27
28 : tally-gc-maps ( gc-maps -- seq/f )
29     [ f ] [ {
30         [ [ scrub-d>> length ] map supremum ]
31         [ [ scrub-r>> length ] map supremum ]
32         [ [ gc-root-offsets ] map largest-spill-slot ]
33         [ [ derived-root-offsets ] map [ keys ] map largest-spill-slot ]
34         [ length ]
35     } cleave 5 narray ] if-empty ;
36
37 ! Like word>gc-info but uses the compiler
38 : word>gc-info-expected ( word -- seq/f )
39     test-regs first cfg>gc-maps tally-gc-maps ;
40
41 : same-gc-info? ( compiler-gc-info gc-info -- ? )
42     [ struct-slot-values = ]
43     [ [ not ] dip return-address-count>> 0 = and ] 2bi or ;
44
45 : base-pointer-groups-expected ( word -- seq )
46     test-regs first cfg>gc-maps [ derived-root-offsets { } like ] { } map-as ;
47
48 : base-pointer-groups-decoded ( word -- seq )
49     word>gc-maps [
50         second second [ swap 2array ] map-index
51         [ nip -1 = ] assoc-reject
52     ] map ;
53
54 ! byte-array>bit-array
55 {
56     ?{
57         t t t t f t t t
58         t f f f f f f f
59     }
60 } [
61     B{ 239 1 } byte-array>bit-array
62 ] unit-test
63
64 { ?{ t t t t t t t t } } [ B{ 255 } byte-array>bit-array ] unit-test
65
66 ! word>gc-maps
67 { f } [
68     \ effects:<effect> word>gc-maps empty?
69 ] unit-test
70
71 { f } [
72     \ + word>gc-maps empty?
73 ] unit-test
74
75 { { } } [
76     \ word>gc-maps word>gc-maps
77 ] unit-test
78
79 ! Big test
80 { { } } [
81     all-words [ normal? ] filter 50 sample
82     [ [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info? ] reject
83 ] unit-test
84
85
86 ! Originally from llvm.types, but llvm moved to unmaintained
87 TYPEDEF: void* LLVMTypeRef
88 TYPEDEF: void* LLVMTypeHandleRef
89 FUNCTION: LLVMTypeRef LLVMResolveTypeHandle ( LLVMTypeHandleRef TypeHandle )
90 FUNCTION: LLVMTypeHandleRef LLVMCreateTypeHandle ( LLVMTypeRef PotentiallyAbstractTy )
91 FUNCTION: void LLVMRefineType ( LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy )
92 FUNCTION: void LLVMDisposeTypeHandle ( LLVMTypeHandleRef TypeHandle )
93
94 : resolve-types ( typeref typeref -- typeref )
95     over LLVMCreateTypeHandle [ LLVMRefineType ] dip
96     [ LLVMResolveTypeHandle ] keep LLVMDisposeTypeHandle ;
97
98 ! base-pointer-groups
99 { t } [
100     \ resolve-types
101     [ base-pointer-groups-expected ] [ base-pointer-groups-decoded ] bi =
102 ] unit-test
103
104
105 ! Tough words #1227
106 { t } [
107     \ resolve-types
108     [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
109 ] unit-test
110
111 { t } [
112     \ opencl:cl-queue-kernel
113     [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
114 ] unit-test
115
116 { t } [
117     \ crypto.aes.utils:bytes>words
118     [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
119 ] unit-test
120
121 { t } [
122     \ cpu.x86.features.private:(sse-version)
123     [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
124 ] unit-test
125
126 ! Ensure deterministic gc map generation.
127 : recompile-word>gc-info ( word -- gc-info )
128     [ 1array compile ] keep word>gc-info ;
129
130 : deterministic-gc-info? ( word -- ? )
131     20 swap '[
132         _ recompile-word>gc-info struct-slot-values
133         dup last 0 = [ drop f ] when
134     ] replicate all-equal? ;
135
136 { t t } [
137     \ opencl:cl-queue-kernel deterministic-gc-info?
138     \ gml.coremath:gml-determinant deterministic-gc-info?
139 ] unit-test