]> gitweb.factorcode.org Git - factor.git/blob - extra/tools/gc-decode/gc-decode-tests.factor
22041fca867e13ca8bdcf73f58ac71d25994458e
[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 {
28     { }
29 } [
30     \ decode-gc-maps word>gc-info scrub-bits
31 ] unit-test
32
33 ! decode-gc-maps
34 { f } [
35     \ effects:<effect> decode-gc-maps empty?
36 ] unit-test
37
38 { f } [
39     \ + decode-gc-maps empty?
40 ] unit-test
41
42 ! read-gc-maps
43 { { } } [
44     \ decode-gc-maps decode-gc-maps
45 ] unit-test
46
47 : cfg>gc-maps ( cfg -- gc-maps )
48     cfg>insns [ gc-map-insn? ] filter [ gc-map>> ] map
49     [ gc-map-needed? ] filter ;
50
51 : tally-gc-maps ( gc-maps -- seq/f )
52     [ f ] [ {
53         [ [ scrub-d>> length ] map supremum ]
54         [ [ scrub-r>> length ] map supremum ]
55         [ [ gc-root-offsets ] map largest-spill-slot ]
56         [ [ derived-root-offsets ] map [ keys ] map largest-spill-slot ]
57         [ length ]
58     } cleave 5 narray ] if-empty ;
59
60 ! Like word>gc-info but uses the compiler
61 : word>gc-info-expected ( word -- seq/f )
62     test-regs first dup stack-frame>> stack-frame
63     [ cfg>gc-maps tally-gc-maps ] with-variable ;
64
65 : same-gc-info? ( compiler-gc-info gc-info -- ? )
66     [ struct-slot-values = ]
67     [ [ not ] dip return-address-count>> 0 = and ] 2bi or ;
68
69 ! Do it also for a bunch of random words
70 : normal? ( word -- ? )
71     { [ generic? ] [ primitive? ] [ inline? ] [ no-compile? ] } 1|| not ;
72
73 { { } } [
74     all-words [ normal? ] filter 50 sample
75     [ [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info? not ] filter
76 ] unit-test
77
78 : base-pointer-groups-expected ( word -- seq )
79     test-regs first dup stack-frame>> stack-frame [
80         cfg>gc-maps [ derived-root-offsets { } like ] { } map-as
81     ] with-variable ;
82
83 : base-pointer-groups-decoded ( word -- seq )
84     word>gc-info base-pointer-groups [
85         [ swap 2array ] map-index [ nip -1 = not ] assoc-filter
86     ] map ;
87
88 ! base-pointer-groups
89 { t } [
90     \ llvm.types:resolve-types
91     [ base-pointer-groups-expected ] [ base-pointer-groups-decoded ] bi =
92 ] unit-test
93
94 ! Tough words #1227
95 { t } [
96     \ llvm.types:resolve-types
97     [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
98 ] unit-test
99
100 { t } [
101     \ opencl:cl-queue-kernel
102     [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
103 ] unit-test
104
105 { t } [
106     \ crypto.aes.utils:bytes>words
107     [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
108 ] unit-test
109
110 { t } [
111     \ cpu.x86.features.private:(sse-version)
112     [ word>gc-info-expected ] [ word>gc-info ] bi same-gc-info?
113 ] unit-test
114
115 ! Ensure deterministic gc map generation.
116 : recompile-word>gc-info ( word -- gc-info )
117     [ 1array compile ] keep word>gc-info ;
118
119 : deterministic-gc-info? ( word -- ? )
120     20 swap '[
121         _ recompile-word>gc-info struct-slot-values
122         dup last 0 = [ drop f ] when
123     ] replicate all-equal? ;
124
125
126 { t } [
127     \ opencl:cl-queue-kernel deterministic-gc-info?
128 ] unit-test