@@ -13,7 +13,7 @@ class PeekPokeAPISpec extends AnyFunSpec with ChiselSim with Matchers {
13
13
14
14
import PeekPokeTestModule ._
15
15
16
- val numTests = 50
16
+ val numTests = 20
17
17
18
18
describe(" PeekPokeAPI with TestableData" ) {
19
19
val w = 32
@@ -150,7 +150,6 @@ class PeekPokeAPISpec extends AnyFunSpec with ChiselSim with Matchers {
150
150
simulate(new PeekPokeTestModule (w)) { dut =>
151
151
assert(w == dut.io.in.bits.a.getWidth)
152
152
val vecDim = dut.vecDim
153
- val truncationMask = (BigInt (1 ) << w) - 1
154
153
155
154
dut.io.in.bits.poke(
156
155
chiselTypeOf(dut.io.in.bits).Lit (
@@ -172,12 +171,11 @@ class PeekPokeAPISpec extends AnyFunSpec with ChiselSim with Matchers {
172
171
thrown.getMessage must include(" observed value UInt<32>(3) != UInt<3>(5)" )
173
172
}
174
173
175
- it(" reports failed Record expects correctly " ) {
174
+ it(" should correctly report failed expect() on a Record " ) {
176
175
val thrown = the[FailedExpectationException [_]] thrownBy {
177
176
simulate(new PeekPokeTestModule (w)) { dut =>
178
177
assert(w == dut.io.in.bits.a.getWidth)
179
178
val vecDim = dut.vecDim
180
- val truncationMask = (BigInt (1 ) << w) - 1
181
179
182
180
dut.io.in.bits.poke(
183
181
chiselTypeOf(dut.io.in.bits).Lit (
@@ -210,12 +208,11 @@ class PeekPokeAPISpec extends AnyFunSpec with ChiselSim with Matchers {
210
208
thrown.getMessage must include(" element 'vDot'" )
211
209
}
212
210
213
- it(" should report failed expect of Records with Vec fields correctly " ) {
211
+ it(" should correctly report failed expect() on Records with Vec fields" ) {
214
212
val thrown = the[FailedExpectationException [_]] thrownBy {
215
213
simulate(new PeekPokeTestModule (w)) { dut =>
216
214
assert(w == dut.io.in.bits.a.getWidth)
217
215
val vecDim = dut.vecDim
218
- val truncationMask = (BigInt (1 ) << w) - 1
219
216
220
217
dut.io.in.bits.poke(
221
218
chiselTypeOf(dut.io.in.bits).Lit (
@@ -244,5 +241,208 @@ class PeekPokeAPISpec extends AnyFunSpec with ChiselSim with Matchers {
244
241
thrown.getMessage must include(" dut.io.out.bits.expect(expRecord)" )
245
242
thrown.getMessage must include(" element 'vOutProduct'" )
246
243
}
244
+
245
+ it(" should support expectPartial() for Records and Vecs" ) {
246
+ simulate(new PeekPokeTestModule (w)) { dut =>
247
+ assert(w == dut.io.in.bits.a.getWidth)
248
+ val vecDim = dut.vecDim
249
+ for {
250
+ _ <- 0 until numTests
251
+ a = BigInt (w, rand)
252
+ b = BigInt (w, rand)
253
+ v1 = Seq .fill(vecDim)(BigInt (w, rand))
254
+ v2 = Seq .fill(vecDim)(BigInt (w, rand))
255
+ op <- TestOp .all
256
+ } {
257
+
258
+ dut.io.in.bits.poke(
259
+ chiselTypeOf(dut.io.in.bits).Lit (
260
+ _.a -> a.U ,
261
+ _.b -> b.U ,
262
+ _.v1 -> Vec .Lit (v1.map(_.U (w.W )): _* ),
263
+ _.v2 -> Vec .Lit (v2.map(_.U (w.W )): _* )
264
+ )
265
+ )
266
+ dut.io.in.valid.poke(true )
267
+ dut.io.op.poke(op)
268
+ dut.clock.step()
269
+ dut.io.in.valid.poke(false )
270
+
271
+ val expectedScalar = calcExpectedScalarOpResult(op, a, b, w)
272
+ val expectedCmp = calcExpectedCmp(a, b)
273
+ val expectedVSum = calcExpectedVSum(v1, v2, w)
274
+ val expVecProduct = calcExpectedVecProduct(v1, v2, w)
275
+ val expVecProductPartial = chiselTypeOf(dut.io.out.bits.vOutProduct).Lit (
276
+ // 0 -> expVecProduct(0)
277
+ // 2 -> expVecProduct(2)
278
+ )
279
+ val expVDot = calcExpectedVDot(v1, v2, w)
280
+
281
+ dut.io.out.bits.vOutProduct.expectPartial(expVecProductPartial)
282
+
283
+ val expectedBitsPartial1 = chiselTypeOf(dut.io.out.bits).Lit (
284
+ // c -> not set
285
+ _.cmp -> expectedCmp,
286
+ // vSum -> not set
287
+ _.vDot -> expVDot,
288
+ _.vOutProduct -> expVecProduct
289
+ )
290
+
291
+ val expectedBitsPartial2 = chiselTypeOf(dut.io.out.bits).Lit (
292
+ _.c -> expectedScalar.U ,
293
+ // cmp -> not set
294
+ _.vSum -> expectedVSum,
295
+ // vDot -> not set
296
+ _.vOutProduct -> expVecProductPartial
297
+ )
298
+
299
+ dut.io.out.bits.expectPartial(expectedBitsPartial1)
300
+
301
+ dut.io.out.bits.expectPartial(expectedBitsPartial2)
302
+
303
+ dut.io.out.expectPartial(
304
+ chiselTypeOf(dut.io.out).Lit (
305
+ _.valid -> true .B ,
306
+ _.bits -> expectedBitsPartial1
307
+ )
308
+ )
309
+ dut.io.out.expectPartial(
310
+ chiselTypeOf(dut.io.out).Lit (
311
+ _.valid -> true .B
312
+ // bits -> not set
313
+ )
314
+ )
315
+ dut.io.out.expectPartial(
316
+ chiselTypeOf(dut.io.out).Lit (
317
+ // valid -> not set
318
+ _.bits -> expectedBitsPartial1
319
+ )
320
+ )
321
+ dut.io.out.expectPartial(
322
+ chiselTypeOf(dut.io.out).Lit (
323
+ // valid -> not set
324
+ _.bits -> expectedBitsPartial2
325
+ )
326
+ )
327
+ }
328
+ }
329
+ }
330
+
331
+ it(" should support expectPartial() for partially initialized Vecs" ) {
332
+ val w = 8
333
+ simulate(new PeekPokeTestModule (w)) { dut =>
334
+ assert(w == dut.io.in.bits.a.getWidth)
335
+ val vecDim = dut.vecDim
336
+ for {
337
+ _ <- 0 until numTests
338
+ a = BigInt (w, rand)
339
+ b = BigInt (w, rand)
340
+ v1 = Seq .fill(vecDim)(BigInt (w, rand))
341
+ v2 = Seq .fill(vecDim)(BigInt (w, rand))
342
+ op <- TestOp .all
343
+ } {
344
+ dut.io.in.bits.poke(
345
+ chiselTypeOf(dut.io.in.bits).Lit (
346
+ _.a -> a.U ,
347
+ _.b -> b.U ,
348
+ _.v1 -> Vec .Lit (v1.map(_.U (w.W )): _* ),
349
+ _.v2 -> Vec .Lit (v2.map(_.U (w.W )): _* )
350
+ )
351
+ )
352
+
353
+ val expVecProduct = calcExpectedVecProduct(v1, v2, w)
354
+ dut.io.in.valid.poke(true )
355
+ dut.io.op.poke(op)
356
+ dut.clock.step()
357
+ dut.io.in.valid.poke(false )
358
+ val expVecProductPartial = chiselTypeOf(dut.io.out.bits.vOutProduct).Lit (
359
+ // TODO: uncommenting the following line throws:
360
+ // java.util.NoSuchElementException: key not found: UInt<16>(...) from AddVecLiteralConstructor.Lit() Unrelated bug?
361
+
362
+ // 0 -> expVecProduct.head
363
+ )
364
+ dut.io.out.bits.vOutProduct.expectPartial(expVecProductPartial)
365
+ }
366
+ }
367
+ }
368
+
369
+ it(" should correctly report failed expectPartial for Aggregates" ) {
370
+ val thrown = the[FailedExpectationException [_]] thrownBy {
371
+ val w = 16
372
+ simulate(new PeekPokeTestModule (w)) { dut =>
373
+ assert(w == dut.io.in.bits.a.getWidth)
374
+ val vecDim = dut.vecDim
375
+
376
+ dut.io.in.bits.poke(
377
+ chiselTypeOf(dut.io.in.bits).Lit (
378
+ _.a -> 1 .U ,
379
+ _.b -> 2 .U ,
380
+ _.v1 -> Vec .Lit (Seq .fill(vecDim)(3 .U (w.W )): _* ),
381
+ _.v2 -> Vec .Lit (Seq .fill(vecDim)(4 .U (w.W )): _* )
382
+ )
383
+ )
384
+ dut.io.in.valid.poke(1 )
385
+ dut.io.op.poke(TestOp .Add )
386
+ dut.clock.step()
387
+
388
+ val expRecord = chiselTypeOf(dut.io.out.bits).Lit (
389
+ // c -> not set
390
+ _.cmp -> CmpResult .LT ,
391
+ _.vSum -> Vec .Lit (Seq .fill(vecDim)(7 .U ((w + 1 ).W )): _* ),
392
+ _.vDot -> 36 .U ((2 * w + vecDim - 1 ).W ),
393
+ _.vOutProduct -> Vec .Lit (
394
+ Seq .fill(vecDim)(
395
+ // initializing only half of the elements for each inner Vec
396
+ chiselTypeOf(dut.io.out.bits.vOutProduct.head)
397
+ .Lit (Seq .tabulate(vecDim / 2 )(i => i -> (5 + i).U ((2 * w).W )): _* )
398
+ ): _*
399
+ )
400
+ )
401
+ dut.io.out.bits.expectPartial(expRecord, " my " + " custom message" )
402
+ }
403
+ }
404
+ thrown.getMessage must include(" dut.io.out.bits.expectPartial(expRecord, \" my \" + \" custom message\" )" )
405
+ thrown.getMessage must include(" Observed value: 'UInt<32>(12)'" )
406
+ thrown.getMessage must include(" Expected value: 'UInt<32>(5)'" )
407
+ thrown.getMessage must include(" element 'vOutProduct'" )
408
+ thrown.getMessage must include(" my custom message" )
409
+ }
410
+
411
+ it(" should fail expect() with a partially initialized Aggregate" ) {
412
+ val thrown = the[UninitializedElementException ] thrownBy {
413
+ simulate(new PeekPokeTestModule (w)) { dut =>
414
+ assert(w == dut.io.in.bits.a.getWidth)
415
+ val vecDim = dut.vecDim
416
+ val v1 = Vec .Lit (Seq .fill(vecDim)(3 .U (w.W )): _* )
417
+ val v2 = Vec .Lit (Seq .fill(vecDim)(4 .U (w.W )): _* )
418
+
419
+ dut.io.in.bits.poke(
420
+ chiselTypeOf(dut.io.in.bits).Lit (
421
+ _.a -> 1 .U ,
422
+ _.b -> 2 .U ,
423
+ _.v1 -> v1,
424
+ _.v2 -> v2
425
+ )
426
+ )
427
+ dut.io.in.valid.poke(true )
428
+ dut.io.op.poke(TestOp .Add )
429
+ dut.clock.step()
430
+
431
+ val expVecProduct = calcExpectedVecProduct(v1, v2, w)
432
+
433
+ val expRecord = chiselTypeOf(dut.io.out.bits).Lit (
434
+ _.c -> 3 .U ,
435
+ // _.cmp -> CmpResult.LT,
436
+ _.vSum -> Vec .Lit (Seq .fill(vecDim)(7 .U ((w + 1 ).W )): _* ),
437
+ _.vDot -> 36 .U ((2 * w + vecDim - 1 ).W ),
438
+ _.vOutProduct -> expVecProduct
439
+ )
440
+ dut.io.out.bits.expect(expRecord)
441
+ }
442
+ }
443
+ thrown.getMessage must include(" dut.io.out.bits.expect(expRecord)" )
444
+ thrown.getMessage must include(" Element 'cmp'" )
445
+ thrown.getMessage must include(" not initialized" )
446
+ }
247
447
}
248
448
}
0 commit comments