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