]> gitweb.factorcode.org Git - factor.git/blob - extra/tools/image-analyzer/gc-info/gc-info-tests.factor
tools.image-analyzer.gc-info.tests: fix tc so it works on windows
[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.short-circuit compiler compiler.cfg
3 compiler.cfg.debugger compiler.cfg.instructions
4 compiler.cfg.linearization compiler.codegen.gc-maps compiler.units fry
5 generic grouping io io.encodings.binary io.streams.byte-array kernel
6 literals math namespaces random sequences system tools.image-analyzer.gc-info
7 tools.image-analyzer.utils tools.test vm vocabs words ;
8 IN: tools.image-analyzer.gc-info.tests
9 QUALIFIED: cpu.x86.features.private
10 QUALIFIED: crypto.aes.utils
11 QUALIFIED: effects
12 QUALIFIED: gtk-samples.opengl
13 QUALIFIED: opencl
14
15 : normal? ( word -- ? )
16     { [ generic? ] [ primitive? ] [ inline? ] [ no-compile? ] } 1|| not ;
17
18 : word>gc-info ( word -- gc-info )
19     word>byte-array binary <byte-reader> <backwards-reader> [
20         gc-info read-struct-safe
21     ] with-input-stream ;
22
23 : cfg>gc-maps ( cfg -- gc-maps )
24     cfg>insns [ gc-map-insn? ] filter [ gc-map>> ] map
25     [ gc-map-needed? ] filter ;
26
27 : tally-gc-maps ( gc-maps -- seq/f )
28     [ f ] [
29         [ [ gc-root-offsets ] map largest-spill-slot ]
30         [ [ derived-root-offsets ] map [ keys ] map largest-spill-slot ]
31         [ length ] tri 3array
32     ] if-empty ;
33
34 ! Like word>gc-info but uses the compiler
35 : word>gc-info-expected ( word -- seq/f )
36     test-regs first [ cfg set ] [ cfg>gc-maps tally-gc-maps ] bi ;
37
38 ! Handle f f as input. Deferred words don't have any gc-info. See #1394.
39 : same-gc-info? ( compiler-gc-info/f gc-info/f -- ? )
40     2dup = [
41         2drop t
42     ] [
43         [ struct-slot-values = ]
44         [ [ not ] dip return-address-count>> 0 = and ] 2bi or
45     ] if ;
46
47 : base-pointer-groups-expected ( word -- seq )
48     test-regs first cfg>gc-maps [ derived-root-offsets { } like ] { } map-as ;
49
50 : base-pointer-groups-decoded ( word -- seq )
51     word>gc-maps [
52         second second [ swap 2array ] map-index
53         [ nip -1 = ] assoc-reject
54     ] map ;
55
56 ! byte-array>bit-array
57 {
58     ?{
59         t t t t f t t t
60         t f f f f f f f
61     }
62 } [
63     B{ 239 1 } byte-array>bit-array
64 ] unit-test
65
66 { ?{ t t t t t t t t } } [ B{ 255 } byte-array>bit-array ] unit-test
67
68 ! word>gc-maps
69 { f } [
70     \ effects:<effect> word>gc-maps empty?
71 ] unit-test
72
73 cpu x86.64? [
74     {
75         ! The difference is because Windows stack references are
76         ! longer because of the home space.
77         { ${ os windows? 156 155 ? { ?{ f t t t t } { } } } }
78     } [
79         \ effects:<effect> word>gc-maps
80     ] unit-test
81 ] when
82
83 { f } [
84     \ + word>gc-maps empty?
85 ] unit-test
86
87 { { } } [
88     \ word>gc-maps word>gc-maps
89 ] unit-test
90
91 ! Big test
92 { { } } [
93     all-words [ normal? ] filter 50 sample
94     [ [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info? ] reject
95 ] unit-test
96
97 ! Originally from llvm.types, but llvm moved to unmaintained
98 TYPEDEF: void* LLVMTypeRef
99 TYPEDEF: void* LLVMTypeHandleRef
100 FUNCTION: LLVMTypeRef LLVMResolveTypeHandle ( LLVMTypeHandleRef TypeHandle )
101 FUNCTION: LLVMTypeHandleRef LLVMCreateTypeHandle ( LLVMTypeRef PotentiallyAbstractTy )
102 FUNCTION: void LLVMRefineType ( LLVMTypeRef AbstractTy, LLVMTypeRef ConcreteTy )
103 FUNCTION: void LLVMDisposeTypeHandle ( LLVMTypeHandleRef TypeHandle )
104
105 : resolve-types ( typeref typeref -- typeref )
106     over LLVMCreateTypeHandle [ LLVMRefineType ] dip
107     [ LLVMResolveTypeHandle ] keep LLVMDisposeTypeHandle ;
108
109 ! base-pointer-groups
110 { t } [
111 \ resolve-types
112     [ base-pointer-groups-expected ] [ base-pointer-groups-decoded ] bi =
113 ] unit-test
114
115 ! Tough words #1227
116 { t } [
117     \ resolve-types
118     [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
119 ] unit-test
120
121 { t } [
122     \ opencl:cl-queue-kernel
123     [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
124 ] unit-test
125
126 { t } [
127     \ crypto.aes.utils:bytes>words
128     [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
129 ] unit-test
130
131 { t } [
132     \ cpu.x86.features.private:(sse-version)
133     [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
134 ] unit-test
135
136 ! #1436
137 { t } [
138     \ gtk-samples.opengl:opengl-main
139     [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
140 ] unit-test
141
142 ! Ensure deterministic gc map generation.
143 : recompile-word>gc-info ( word -- gc-info )
144     [ 1array compile ] keep word>gc-info ;
145
146 : deterministic-gc-info? ( word -- ? )
147     20 swap '[
148         _ recompile-word>gc-info struct-slot-values
149         dup last 0 = [ drop f ] when
150     ] replicate all-equal? ;
151
152 { t } [
153     \ opencl:cl-queue-kernel deterministic-gc-info?
154 ] unit-test
155
156
157
158 ! TODO: try on 32 bit \ feedback-format: