title: Testing of a RegisterFile in Chisel
body: <p>I want to test a vector of registers (a registerFile). Below is a function which reads the indexed value of a registerFile:-</p>
  
  <pre><code>class ViewRegFile(regnum: Int, size: Int) extends Module {
    val io = IO(new Bundle {
      val registers =  Input(Reg(Vec(regnum,UInt(size.W))))
      val inputs = Input(UInt(size.W))
      val ok = Input(UInt(1.W))
      val values = Output(UInt(size.W))
    })
    val buffer = RegInit(VecInit(Seq.fill(regnum)(0.U(size.W)))) // so we have a reset to buffer regmap
    when(io.ok === 1.U){
    for(i&lt;-0 until regnum) {
    buffer(i)  := io.registers(i)
    }
    }
    val itr = io.inputs
    io.values := buffer(itr)
  }
  </code></pre>
  
  <p>The above code takes the registerFile <em>registers</em>, which has <em>regnum</em> registers of size <em>size</em>. I am indexing the registerFile using variable <em>inputs</em> and output the indexed value of the registerFile through the variable <em>values</em>.</p>
  
  <p>To test the functionality I created a registerFile in a testbench, initialized some values to the File and wanted to the read the outputs out using the above written function <em>ViewRegFile</em>. I am stuck now as to where could I have gone wrong in the implementation. Below is the testbench I tried making:-</p>
  
  <pre><code>import java.io.File
  import chisel3._   //needed to declare testbench (tb) registerFile
  import chisel3.iotesters
  import chisel3.iotesters.{ChiselFlatSpec, Driver, PeekPokeTester}
  
  class RegUnitTester(c: ViewRegFile, val regnum: Int, val size:Int) extends PeekPokeTester(c) {
   private val mod = c
  val register = RegInit(VecInit(Seq.fill(regnum)(0.U(size.W)))) // tb registerFile
  val val1 = 1434.U(size.W)
  val val2 = 9082.U(size.W)
  register(1) := val1
  register(2) := val2 
  poke(mod.io.registers, register) //loaded tb registerFile to function registerFile
  for(j&lt;- 0 until regnum) {
    poke(mod.io.inputs, j) //desired values from function registerFile
    poke(mod.io.ok,1)
    step(1)
    poke(mod.io.ok,0)
    peek(mod.io.values) } // indexed output
  }
  
  object RegTester extends App {
    println("Testing RegFile Viewer")
    iotesters.Driver.execute(Array("--target-dir", "generated", "--generate-vcd-output", "on"), () =&gt; new ViewRegFile(4, 16)) {
      c =&gt; new RegUnitTester(c,4,16)
    }
  }
  </code></pre>
  
  <p>and <em>poke</em> is failing with the error :</p>
  
  <pre><code>[error] overloaded method value poke with alternatives: 
  [error]   (signal: chisel3.Aggregate,value: IndexedSeq[BigInt])Unit &lt;and&gt;
  [error]   (signal: chisel3.Bundle,map: Map[String,BigInt])Unit &lt;and&gt;
  [error]   [T &lt;: chisel3.Element](signal: T, value: Long)(implicit evidence$10: chisel3.iotesters.Pokeable[T])Unit &lt;and&gt;
  [error]   [T &lt;: chisel3.Element](signal: T, value: Int)(implicit evidence$9: chisel3.iotesters.Pokeable[T])Unit &lt;and&gt;
  [error]   [T &lt;: chisel3.Element](signal: T, value: BigInt)(implicit evidence$8: chisel3.iotesters.Pokeable[T])Unit &lt;and&gt;
  [error]   (path: String,value: Long)Unit &lt;and&gt;
  [error]   (path: String,value: Int)Unit &lt;and&gt;
  [error]   (path: String,value: BigInt)Unit
  [error] poke(mod.io.registers, register)
  </code></pre>