]> gitweb.factorcode.org Git - factor.git/blob - extra/tools/gc-decode/gc-decode-tests.factor
cb3a3df5f18d0a18e02b212fb76056367315a643
[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 f t t t t } ! 64-bit
31         ?{ t t t t f f f f f t t t t } ! 32-bit TODO
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         [ [ gc-root-offsets ] map largest-spill-slot ]
64         [ [ derived-root-offsets ] map [ keys ] map largest-spill-slot ]
65         [ length ]
66     } cleave 5 narray ] if-empty ;
67
68 ! Like word>gc-info but uses the compiler
69 : word>gc-info-expected ( word -- seq/f )
70     test-regs first dup stack-frame>> stack-frame
71     [ cfg>gc-maps tally-gc-maps ] with-variable ;
72
73 : same-gc-info? ( compiler-gc-info gc-info -- ? )
74     [ struct-slot-values = ]
75     [ [ not ] dip return-address-count>> 0 = and ] 2bi or ;
76
77 ! Do it also for a bunch of random words
78 : normal? ( word -- ? )
79     { [ generic? ] [ primitive? ] [ inline? ] [ no-compile? ] } 1|| not ;
80
81 { { } } [
82     all-words [ normal? ] filter 50 sample
83     [ [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info? not ] filter
84 ] unit-test
85
86 : base-pointer-groups-expected ( word -- seq )
87     test-regs first dup stack-frame>> stack-frame [
88         cfg>gc-maps [ derived-root-offsets { } like ] { } map-as
89     ] with-variable ;
90
91 : base-pointer-groups-decoded ( word -- seq )
92     word>gc-info base-pointer-groups [
93         [ swap 2array ] map-index [ nip -1 = not ] assoc-filter
94     ] map ;
95
96 ! base-pointer-groups
97 { t } [
98     \ llvm.types:resolve-types
99     [ base-pointer-groups-expected ] [ base-pointer-groups-decoded ] bi =
100 ] unit-test
101
102 ! Tough words #1227
103 { t } [
104     \ llvm.types:resolve-types
105     [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
106 ] unit-test
107
108 { t } [
109     \ opencl:cl-queue-kernel
110     [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
111 ] unit-test
112
113 { t } [
114     \ crypto.aes.utils:bytes>words
115     [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
116 ] unit-test
117
118 { t } [
119     \ cpu.x86.features.private:(sse-version)
120     [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
121 ] unit-test
122
123 ! Ensure deterministic gc map generation.
124 : recompile-word>gc-info ( word -- gc-info )
125     [ 1array compile ] keep word>gc-info ;
126
127 : deterministic-gc-info? ( word -- ? )
128     20 swap '[
129         _ recompile-word>gc-info struct-slot-values
130         dup last 0 = [ drop f ] when
131     ] replicate all-equal? ;
132
133
134 { t } [
135     \ opencl:cl-queue-kernel deterministic-gc-info?
136 ] unit-test