|
| 1 | +// Copyright 2019 IBM |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package esptests.examples |
| 16 | + |
| 17 | +import chisel3._ |
| 18 | +import chisel3.iotesters.{ChiselFlatSpec, Driver, AdvTester} |
| 19 | + |
| 20 | +import esp.examples.ShiftArray |
| 21 | + |
| 22 | +class ShiftArrayTester[A <: Bits](dut: ShiftArray[A]) extends AdvTester(dut) { |
| 23 | + def init(): Unit = { |
| 24 | + Seq(dut.io.in.valid).map(p => wire_poke(p, false)) |
| 25 | + } |
| 26 | + |
| 27 | + def load(in: Seq[Int]): Unit = { |
| 28 | + require(in.size % dut.cols == 0) |
| 29 | + in |
| 30 | + .grouped(dut.cols) |
| 31 | + .foreach{ case a => |
| 32 | + wire_poke(dut.io.in.valid, 1) |
| 33 | + a.zipWithIndex.map{ case (b, i) => wire_poke(dut.io.in.bits(i), b) } |
| 34 | + step(1) |
| 35 | + wire_poke(dut.io.in.valid, 0) } |
| 36 | + } |
| 37 | + |
| 38 | + val input: Seq[Int] = 0 until dut.rows * dut.cols |
| 39 | + |
| 40 | + reset(4) |
| 41 | + expect(dut.io.out.valid, false) |
| 42 | + |
| 43 | + init() |
| 44 | + step(1) |
| 45 | + |
| 46 | + load(0 until 9) |
| 47 | + |
| 48 | + expect(dut.io.out.valid, true) |
| 49 | + println(peek(dut.io.out.bits).mkString(", ")) |
| 50 | + |
| 51 | + load(9 until 12) |
| 52 | + expect(dut.io.out.valid, true) |
| 53 | + println(peek(dut.io.out.bits).mkString(", ")) |
| 54 | + |
| 55 | + reset(1) |
| 56 | + expect(dut.io.out.valid, false) |
| 57 | +} |
| 58 | + |
| 59 | +class ShiftArraySpec extends ChiselFlatSpec { |
| 60 | + |
| 61 | + behavior of "ShiftArray" |
| 62 | + |
| 63 | + it should "present a 3x3 array" in { |
| 64 | + Driver(() => new ShiftArray(3, 3, UInt(16.W)), "treadle") { |
| 65 | + dut => new ShiftArrayTester(dut) |
| 66 | + } should be (true) |
| 67 | + } |
| 68 | + |
| 69 | +} |
0 commit comments