Skip to content

Commit

Permalink
Toy example of using instrumentation
Browse files Browse the repository at this point in the history
It monitors and bins signal values
  • Loading branch information
chick committed Oct 25, 2017
1 parent 0d9b7e1 commit d8f0753
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/test/scala/examples/InstrumentingSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// See LICENSE for license details.

package examples

import chisel3._
import chisel3.experimental.FixedPoint
import dsptools.DspTester
import dsptools.numbers._
import org.scalatest.{FlatSpec, Matchers}

//scalastyle:off magic.number

class InstrumentingAdder[T <: Data:Ring](gen:() => T) extends Module {
val io = IO(new Bundle {
val a1: T = Input(gen())
val a2: T = Input(gen())
val c = Output(gen())
})

val register1 = Reg(gen())

register1 := io.a1 + io.a2

io.c := register1
}

class InstrumentingAdderTester[T<:Data:Ring](c: InstrumentingAdder[T]) extends DspTester(c) {
for {
i <- -2.0 to 1.0 by 0.25
j <- -2.0 to 4.0 by 0.5
} {
poke(c.io.a1, i)
poke(c.io.a2, j)
step(1)

val result = peek(c.io.c)

expect(c.io.c, i + j, s"parameterize adder tester $i + $j => $result should have been ${i + j}")
}
}

class InstrumentingAdderSpec extends FlatSpec with Matchers {

behavior of "parameterized adder circuit on blackbox real"

it should "run while being instrumented" in {
def getFixed: FixedPoint = FixedPoint(32.W, 16.BP)

dsptools.Driver.execute(() => new InstrumentingAdder(getFixed _),
Array("-fimbu", "-fimof", "signals.csv", "-fimhb", "16")) { c =>
new InstrumentingAdderTester(c)
} should be (true)
}
}

0 comments on commit d8f0753

Please sign in to comment.