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