To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

TestingBundlesValidators.scala 8.96 KB
Newer Older
Kunshan Wang's avatar
Kunshan Wang committed
1
2
package uvm.ir.textinput

Kunshan Wang's avatar
Kunshan Wang committed
3
4
5
6
7
8
9
10
11
12
13
14
15
import org.scalatest._

import uvm._
import uvm.types._
import uvm.ssavalues._
import uvm.ifuncs._

trait TestingBundlesValidators extends Matchers with ExtraMatchers {
  
  implicit class MagicalOur(b: Bundle) {
    def ty = b.typeNs
    def const = b.globalValueNS
    def globalValue = b.globalValueNS
Kunshan Wang's avatar
Kunshan Wang committed
16
    def globalData = b.globalDataNS
Kunshan Wang's avatar
Kunshan Wang committed
17
18
19
20
21
22
23
    def sig = b.funcSigNs
    def func = b.funcNs
  }

  def validateTypes(bundle: Bundle) {
    val our = bundle
    
Kunshan Wang's avatar
Kunshan Wang committed
24
25
26
27
28
    our ty "@i1" shouldBeATypeIntOf(1)
    our ty "@i8" shouldBeATypeIntOf(8)
    our ty "@i16" shouldBeATypeIntOf(16)
    our ty "@i32" shouldBeATypeIntOf(32)
    our ty "@i64" shouldBeATypeIntOf(64)
Kunshan Wang's avatar
Kunshan Wang committed
29
30
31
32
33
34
35
36
    
    our ty "@f" shouldBeA[TypeFloat] thatsIt
    our ty "@d" shouldBeA[TypeDouble] thatsIt
    
    our ty "@rv" shouldBeA[TypeRef] { _.ty shouldBeA[TypeVoid] thatsIt }
    our ty "@irv" shouldBeA[TypeIRef] { _.ty shouldBeA[TypeVoid] thatsIt }
    our ty "@wrv" shouldBeA[TypeWeakRef] { _.ty shouldBeA[TypeVoid] thatsIt }
    
Kunshan Wang's avatar
Kunshan Wang committed
37
38
    our ty "@ri16" shouldBeA[TypeRef] { _.ty shouldBeATypeIntOf(16)}
    our ty "@ri16_2" shouldBeA[TypeRef] { _.ty shouldBeATypeIntOf(16)}
Kunshan Wang's avatar
Kunshan Wang committed
39
40
41

    our ty "@s0" shouldBeA[TypeStruct] { _.fieldTy shouldBe empty }
    our ty "@s1" shouldBeA[TypeStruct] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
42
43
44
45
      its fieldTy 0 shouldBeATypeIntOf(8)
      its fieldTy 1 shouldBeATypeIntOf(16)
      its fieldTy 2 shouldBeATypeIntOf(32)
      its fieldTy 3 shouldBeATypeIntOf(64)
Kunshan Wang's avatar
Kunshan Wang committed
46
47
48
49
50
      its fieldTy 4 shouldBeA[TypeFloat] thatsIt
      its fieldTy 5 shouldBeA[TypeDouble] thatsIt
      its fieldTy 6 shouldBeA[TypeRef] { _.ty shouldBeA[TypeVoid] thatsIt }
      its fieldTy 7 shouldBeA[TypeIRef] { _.ty shouldBeA[TypeVoid] thatsIt }
      its fieldTy 8 shouldBeA[TypeWeakRef] { _.ty shouldBeA[TypeVoid] thatsIt }
Kunshan Wang's avatar
Kunshan Wang committed
51
52
      its fieldTy 9 shouldBeA[TypeRef] { _.ty shouldBeATypeIntOf(16)}
      its fieldTy 10 shouldBeA[TypeRef] { _.ty shouldBeATypeIntOf(16)}
Kunshan Wang's avatar
Kunshan Wang committed
53
54
55
    }
    
    our ty "@cons" shouldBeA[TypeStruct] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
56
      its fieldTy 0 shouldBeATypeIntOf(64)
Kunshan Wang's avatar
Kunshan Wang committed
57
58
59
60
      its fieldTy 1 shouldBeA[TypeRef] { _.ty shouldBe (our ty "@cons")}
    }
    
    our ty "@a0" shouldBeA[TypeArray] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
61
      its.elemTy shouldBeATypeIntOf(8)
Kunshan Wang's avatar
Kunshan Wang committed
62
63
64
65
66
      its.len shouldEqual 100
    }
    our ty "@a1" shouldBeA[TypeArray] { its =>
      its.elemTy shouldBeA[TypeStruct] { whose =>
        whose fieldTy 0 shouldBeA[TypeDouble] thatsIt
Kunshan Wang's avatar
Kunshan Wang committed
67
        whose fieldTy 1 shouldBeATypeIntOf(64)
Kunshan Wang's avatar
Kunshan Wang committed
68
69
70
71
72
73
74
75
76
77
      }
      its.len shouldEqual 10
    }
    our ty "@a2" shouldBeA[TypeArray] { its =>
      its.elemTy shouldBe (our ty "@a1")
      its.len shouldEqual 10
    }
    
    our ty "@h0" shouldBeA[TypeHybrid] { its =>
      its.fixedPart shouldBeA[TypeVoid] thatsIt
Kunshan Wang's avatar
Kunshan Wang committed
78
      its.varPart shouldBeATypeIntOf(8)
Kunshan Wang's avatar
Kunshan Wang committed
79
80
81
82
83
84
85
    }
    our ty "@h1" shouldBeA[TypeHybrid] { its =>
      its.fixedPart shouldBeA[TypeStruct] { whose =>
        whose fieldTy 0 shouldBe (our ty "@i32")
        whose fieldTy 1 shouldBe (our ty "@i32")
        whose fieldTy 2 shouldBeA[TypeFloat] thatsIt
      }
Kunshan Wang's avatar
Kunshan Wang committed
86
      its.varPart shouldBeATypeIntOf(64)
Kunshan Wang's avatar
Kunshan Wang committed
87
88
89
90
91
92
93
94
95
    }
    
    our ty "@v" shouldBeA[TypeVoid] thatsIt
    
    our ty "@f0" shouldBeA[TypeFunc] { its =>
      its.sig.retTy shouldBeA[TypeVoid] thatsIt
      its.sig.paramTy shouldBe empty
    }
    our ty "@f1" shouldBeA[TypeFunc] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
96
97
      its.sig.retTy shouldBeATypeIntOf(32)
      its.sig paramTy 0 shouldBeATypeIntOf(32)
Kunshan Wang's avatar
Kunshan Wang committed
98
      its.sig.paramTy(1) shouldBeA[TypeIRef] { _.ty shouldBeA[TypeIRef] {
Kunshan Wang's avatar
Kunshan Wang committed
99
        _.ty shouldBeATypeIntOf(8)}
Kunshan Wang's avatar
Kunshan Wang committed
100
101
102
103
104
105
      }
    }
    
    our ty "@th" shouldBeA[TypeThread] thatsIt
    our ty "@st" shouldBeA[TypeStack] thatsIt
    our ty "@tr64" shouldBeA[TypeTagRef64] thatsIt
Kunshan Wang's avatar
Kunshan Wang committed
106
  }
Kunshan Wang's avatar
Kunshan Wang committed
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
  
  def validateConstants(bundle: Bundle) {
    val our = bundle

    our const "@ci8" shouldBeAConstIntOf (8, 127)
    our const "@ci16" shouldBeAConstIntOf (16, 32767)
    our const "@ci32" shouldBeAConstIntOf (32, 2147483647)
    our const "@ci64" shouldBeAConstIntOf (64, 9223372036854775807L)
    
    our const "@ci64neg" shouldBeAConstIntOf (64, BigInt(-42L) & 0xffffffffffffffffL)
    
    our const "@cio64" shouldBeAConstIntOf (64, BigInt("777", 8))
    
    our const "@cix64" shouldBeAConstIntOf (64, BigInt("123456789abcdef0", 16))
    our const "@cixovf" shouldBeAConstIntOf (64, BigInt("ffffffffffffffff", 16))
    our const "@cixovf2" shouldBeAConstIntOf (64, BigInt("8000000000000000", 16))
    
    our const "@cf" shouldBeAConstFloatOf 3.14F
    our const "@cfnan" shouldBeAConstFloatOf nan
    our const "@cfninf" shouldBeAConstFloatOf Float.NegativeInfinity 
    our const "@cfpinf" shouldBeAConstFloatOf Float.PositiveInfinity 
    our const "@cfbits" shouldBeAConstFloatOf exactly(bitsf(0x12345678))
  
    our const "@cd" shouldBeAConstDoubleOf 6.28D
    our const "@cdnan" shouldBeAConstDoubleOf nan
    our const "@cdninf" shouldBeAConstDoubleOf Double.NegativeInfinity 
    our const "@cdpinf" shouldBeAConstDoubleOf Double.PositiveInfinity 
    our const "@cdbits" shouldBeAConstDoubleOf exactly(bitsd(0xfedcba9876543210L))
 
    our const "@cs1" shouldBeA[ConstStruct] { its=>
      its.constTy shouldBeA[TypeStruct] { whose =>
        whose fieldTy 0 shouldBeATypeIntOf(64)
        whose fieldTy 1 shouldBeA[TypeDouble] thatsIt
      }
      its fields 0 shouldBeAConstIntOf (64, 100)
      its fields 1 shouldBeAConstDoubleOf 200.0D
    }
    
    our const "@cs2" shouldBeA[ConstStruct] { its=>
      its.constTy shouldBeA[TypeStruct] { whose =>
        whose fieldTy 0 shouldBeA[TypeDouble] thatsIt
        whose fieldTy 1 shouldBeA[TypeStruct] { where =>
          where fieldTy 0 shouldBeA[TypeFloat] thatsIt
          where fieldTy 1 shouldBeATypeIntOf(64)
        }
        whose fieldTy 2 shouldBeATypeIntOf(32)
      }
      its fields 0 shouldBeAConstDoubleOf 1.0D
      its fields 1 shouldBeA[ConstStruct] { whose =>
        whose fields 0 shouldBeAConstFloatOf 2.0F
        whose fields 1 shouldBeAConstIntOf (64, 3)
      }
      its fields 2 shouldBeAConstIntOf (32, 4)
    }
    
    our const "@cons" shouldBeA[ConstStruct] { its =>
      its.constTy shouldBe (our ty "@Cons")
      its fields 0 shouldBeAConstIntOf (64, 42)
      its fields 1 shouldBeA[ConstNull] { _.ty shouldBeA[TypeRef] { _.ty shouldBe (our ty "@Cons") }}
    }
    
    our const "@cr" shouldBeA[ConstNull] { _.ty shouldBeA[TypeRef] { _.ty shouldBeATypeIntOf(64) }}
    our const "@cir" shouldBeA[ConstNull] { _.ty shouldBeA[TypeIRef] { _.ty shouldBeA[TypeFloat] thatsIt }}
    our const "@cwr" shouldBeA[ConstNull] { _.ty shouldBeA[TypeWeakRef] { _.ty shouldBe (our ty "@Cons") }}
    our const "@cfu" shouldBeA[ConstNull] { _.ty shouldBeA[TypeFunc] { _.sig shouldBeA[FuncSig] { its =>
      its.retTy shouldBeA[TypeVoid] thatsIt
      its.paramTy shouldBe empty
    }}}
    our const "@cth" shouldBeA[ConstNull] { _.ty shouldBeA[TypeThread] thatsIt }
    our const "@cst" shouldBeA[ConstNull] { _.ty shouldBeA[TypeStack] thatsIt }
    
    our globalData "@gi64" shouldBeA[GlobalData] { _.ty shouldBeATypeIntOf(64) }

    our func "@fdummy" shouldBeA[Function] { _.sig shouldBeA[FuncSig] { its =>
      its.retTy shouldBeA[TypeVoid] thatsIt
      its.paramTy shouldBe empty
    }}
  }
  def validateFunctions(bundle: Bundle) {
    val our = bundle
Kunshan Wang's avatar
Kunshan Wang committed
187
188
189
190
191
    
    our sig "@foo" shouldBeA[FuncSig] { its =>
      its.retTy shouldBeA[TypeVoid] thatsIt
      its.paramTy shouldBe empty
    }
Kunshan Wang's avatar
Kunshan Wang committed
192

Kunshan Wang's avatar
Kunshan Wang committed
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
    our sig "@bar" shouldBeA[FuncSig] { its =>
      its.retTy shouldBeATypeIntOf 64
      its paramTy 0 shouldBeATypeIntOf 32
      its paramTy 1 shouldBeATypeIntOf 16
    }
    
    our sig "@baz" shouldBeA[FuncSig] { its =>
      its.retTy shouldBeATypeIntOf 32
      its paramTy 0 shouldBeATypeIntOf 32
      its paramTy 1 shouldBeA[TypeIRef] { _.ty shouldBeA[TypeIRef] {
        _.ty shouldBeATypeIntOf 8
      }}
    }
    
    our sig "@sig_fs" shouldBeA[FuncSig] { its =>
      its.retTy shouldBeA[TypeVoid] thatsIt
      its paramTy 0 shouldBeATypeIntOf 32
    }
    
    our ty "@sig_t" shouldBeA[TypeFunc] { _.sig shouldBe (our sig "@sig_fs") }

    our func "@signal" shouldBeA[Function] { its =>
      its.cfg shouldBe None
      its.sig shouldBeA[FuncSig] { whose =>
        whose.retTy shouldBe (our ty "@sig_t")
        whose paramTy 0 shouldBeATypeIntOf 32
        whose paramTy 1 shouldBe (our ty "@sig_t")
      }
    }
    
    our const "@zero" shouldBeA[ConstInt] { its =>
      its.constTy shouldBeATypeIntOf 32
      its.num shouldBe 0
    }
    
    our func "@main" shouldBeA[Function] { theFunc =>
      val its = theFunc
      its.cfg shouldNot be(None)
      its.cfg.get.func shouldBe theFunc
      its.sig shouldBe (our sig "@baz")
      its.cfg.get.params(0).name shouldBe Some("%argc")
      its.cfg.get.params(1).name shouldBe Some("%argv")
      its.cfg.get.entry.name shouldBe Some("%entry")
      its.cfg.get.bbs.size shouldBe 1
      
    }
    
    our func "@implicitentry" shouldBeA[Function] { its =>
      its.cfg shouldNot be(None)
      its.sig shouldBe (our sig "@foo")
      its.cfg.get.params shouldBe empty
      its.cfg.get.entry.name shouldBe None
      its.cfg.get.bbs.size shouldBe 1
    }
Kunshan Wang's avatar
Kunshan Wang committed
247
  }
Kunshan Wang's avatar
Kunshan Wang committed
248
  
Kunshan Wang's avatar
Kunshan Wang committed
249
250
251
252
  def validateInstructions(bundle: Bundle) {
    val our = bundle

  }
Kunshan Wang's avatar
Kunshan Wang committed
253
}