• Stars
    star
    198
  • Rank 189,941 (Top 4 %)
  • Language
    Scala
  • License
    Other
  • Created over 5 years ago
  • Updated 9 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The batteries-included testing and formal verification library for Chisel-based RTL designs.

chiseltest

Chiseltest is the batteries-included testing and formal verification library for Chisel-based RTL designs. Chiseltest emphasizes tests that are lightweight (minimizes boilerplate code), easy to read and write (understandability), and compose (for better test code reuse).

Installation

To use chisel-testers as a managed dependency, add this in your build.sbt:

libraryDependencies += "edu.berkeley.cs" %% "chiseltest" % "5.0-SNAPSHOT"

Starting with chisel5, please make sure to pick a matching major version, to avoid linking errors. For older versions, if you are also directly depending on the chisel3 library, please make sure that your chisel3 and chiseltest versions match to avoid linking errors.

Writing a Test

ChiselTest integrates with the ScalaTest framework, which provides good IDE and continuous integration support for launching unit tests.

Assuming a typical Chisel project with MyModule defined in src/main/scala/MyModule.scala:

class MyModule extend Module {
    val io = IO(new Bundle {
        val in = Input(UInt(16.W))
        val out = Output(UInt(16.W))
    })

    io.out := RegNext(io.in)
}

Create a new file in src/test/scala/, for example, BasicTest.scala.

In this file:

  1. Add the necessary imports:
    import chisel3._
    import chiseltest._
    import org.scalatest.flatspec.AnyFlatSpec
  2. Create a test class:
    class BasicTest extends AnyFlatSpec with ChiselScalatestTester {
      behavior of "MyModule"
      // test class body here
    }
    • AnyFlatSpec is the default and recommended ScalaTest style for unit testing.
    • ChiselScalatestTester provides testdriver functionality and integration (like signal value assertions) within the context of a ScalaTest environment.
    • For those interested in additional ScalaTest assertion expressibility, Matchers provides additional assertion syntax options. Matchers is optional as it's mainly for Scala-land assertions and does not inter-operate with circuit operations.
  3. In the test class, define a test case:
    it should "do something" in {
      // test case body here
    }
    There can be multiple test cases per test class, and we recommend one test class per Module being tested, and one test case per individual test.
  4. In the test case, define the module being tested:
    test(new MyModule) { c =>
      // test body here
    }
    test automatically runs the default simulator (which is treadle), and runs the test stimulus in the block. The argument to the test stimulus block (c in this case) is a handle to the module under test.
  5. In the test body, use poke, step, and expect operations to write the test:
    c.io.in.poke(0.U)
    c.clock.step()
    c.io.out.expect(0.U)
    c.io.in.poke(42.U)
    c.clock.step()
    c.io.out.expect(42.U)
    println("Last output value :" + c.io.out.peek().litValue)
  6. With your test case complete, you can run all the test cases in your project by invoking ScalaTest. If you're using sbt, you can either run sbt test from the command line, or test from the sbt console. testOnly can also be used to run specific tests.

Usage References

See the test cases for examples:

  • BasicTest shows basic peek, poke, and step functionality
  • QueueTest shows example uses of the DecoupledDriver library, providing functions like enqueueNow, expectDequeueNow, their sequence variants, expectPeek, and expectInvalid. Also, check out the DecoupledDriver implementation, and note that it is not a special case, but code that any user can write.
  • BundleLiteralsSpec shows examples of using bundle literals to poke and expect bundle wires.
    • Note: Bundle literals are still an experimental chisel3 feature and need to be explicitly imported:
      import chisel3.experimental.BundleLiterals._
  • AlutTest shows an example of re-using the same test for different data
  • ShiftRegisterTest shows an example of using fork/join to define a test helper function, where multiple invocations of it are pipelined using fork.

New Constructs

  • fork to spawn threads, and join to block (wait) on a thread. Pokes and peeks/expects to wires from threads are checked during runtime to ensure no collisions or unexpected behavior.
    • forked threads provide a concurrency abstraction for writing testbenches only, without real parallelism. The test infrastructure schedules threads one at a time, with threads running once per simulation cycle.
    • Thread order is deterministic, and attempts to follow lexical order (as it would appear from the code text): forked (child) threads run immediately, then return to the spawning (parent) thread. On future cycles, child threads run before their parent, in the order they were spawned.
    • Only cross-thread operations that round-trip through the simulator (eg, peek-after-poke) are checked. You can do cross-thread operations in Scala (eg, using shared variables) that aren't checked, but it is up to you to make sure they are correct and intuitive. This is not recommended. In the future, we may provide checked mechanisms for communicating between test threads.
  • Regions can be associated with a thread, with fork.withRegion(...), which act as a synchronization barrier within simulator time steps. This can be used to create monitors that run after other main testdriver threads have been run, and can read wires those threads have poked.
  • timescope allows pokes to be scoped - that is, pokes inside the timescope block "disappear" and the wire reverts to its previous value at the end of the block. This fits well with the pattern of assigning a default pull-up/down to a wire, and temporarily overriding that value, for example a Decoupled valid signal defaulting low but driven high during an enqueue transaction. See TimescopeTest for examples.

Simulator Backends

One of our goals is to keep your tests independent of the underlying simulator as much as possible. Thus, in most cases you should be able to choose from one of our four supported backends and get the exact same test results albeit with differences in execution speed and wave dump quality.

We provide full bindings to two popular open-source simulator:

  • treadle: default, fast startup times, slow execution for larger circuits, supports only VCD
  • verilator: enable with VerilatorBackendAnnotation, slow startup, fast execution, supports VCD and FST

We also provide bindings with some feature limitations to:

  • iverilog: open-source, enable with IcarusBackendAnnotation, supports VCD, FST and LXT
  • vcs: commercial, enable with VcsBackendAnnotation, supports VCD and FSDB

Verilator Versions

We currently support the following versions of the verilator simulator:

Frequently Asked Questions

How do I rerun with --full-stacktrace?

Whereas Chisel accepts command-line arguments, chiseltest exposes the underlying annotation interface. You can pass annotations to a test by using .withAnnotations(...), for example:

// Top of file
import chisel3.stage.PrintFullStackTraceAnnotation

// ...

    // Inside your test spec
    test(new MyModule).withAnnotations(Seq(PrintFullStackTraceAnnotation)) { c =>
      // test body here
    }

This will remove the chisel3 stacktrace suppression (ie. at ... ()). However, if you are using ScalaTest, you may notice a shortened stack trace with ... at the end. You can tell ScalaTest to stop suppressing the stack trace by passing -oF to it. For example (using SBT):

$ sbt
> testOnly <spec name> -- -oF

Any arguments after -- pass to ScalaTest directly instead of being interpreted by SBT.

Stability

Most APIs that can be accessed through import chiseltest._ are going to remain stable. We are also trying to keep the API provided through import chiseltest.formal._ relatively stable. All other packages are considered internal and thus might change at any time.

Migrating from chisel-testers / iotesters

Port to new API

The core abstractions (poke, expect, step) are similar to chisel-testers, but the syntax is inverted: instead of doing tester.poke(wire, value) with a Scala number value, in ChiselTest you would write wire.poke(value) with a Chisel literal value. Furthermore, as no reference to the tester context is needed, test helper functions can be defined outside a test class and written as libraries.

PeekPokeTester compatibility

chiseltest now provides a compatibility layer that makes it possible to re-use old PeekPokeTester based tests with little to no changes to the code. We ported the majority of tests from the chisel-testers repository to our new compatibility layer. While the test itself can mostly remain unchanged, the old Driver is removed and instead tests are launched with the new test syntax.

Hardware testers

Hardware testers are synthesizeable tests, most often extending the BasicTester class provided by chisel3. You can now directly use these tests with chiseltest through the runUntilStop function.

More Repositories

1

chipyard

An Agile RISC-V SoC Design Framework with in-order cores, out-of-order cores, accelerators, and more
Scala
1,415
star
2

gemmini

Berkeley's Spatial Array Generator
Scala
668
star
3

chisel-tutorial

chisel tutorial exercises and answers
Scala
643
star
4

riscv-sodor

educational microarchitectures for risc-v isa
Scala
641
star
5

riscv-mini

Simple RISC-V 3-stage Pipeline in Chisel
Scala
488
star
6

chisel2-deprecated

Scala
387
star
7

fpga-zynq

Support for Rocket Chip on Zynq FPGAs
Tcl
378
star
8

berkeley-hardfloat

Scala
264
star
9

hammer

Hammer: Highly Agile Masks Made Effortlessly from RTL
Python
231
star
10

berkeley-softfloat-3

SoftFloat release 3
C
208
star
11

dsptools

A Library of Chisel3 Tools for Digital Signal Processing
Scala
206
star
12

riscv-torture

RISC-V Torture Test
Scala
152
star
13

constellation

A Chisel RTL generator for network-on-chip interconnects
Scala
143
star
14

hwacha

Microarchitecture implementation of the decoupled vector-fetch accelerator
Scala
139
star
15

esp-llvm

UCB-BAR fork of LLVM! NOT UPSTREAM RISCV LLVM
C++
123
star
16

midas

FPGA-Accelerated Simulation Framework Automatically Transforming Arbitrary RTL
Scala
91
star
17

testchipip

Scala
74
star
18

sha3

Verilog
73
star
19

onnxruntime-riscv

Fork of upstream onnxruntime focused on supporting risc-v accelerators
C++
70
star
20

cosa

A scheduler for spatial DNN accelerators that generate high-performance schedules in one shot using mixed integer programming (MIP)
Python
66
star
21

ccbench

Memory System Microbenchmarks
C
57
star
22

zscale

Z-scale Microarchitectural Implementation of RV32 ISA
C
51
star
23

gemmini-rocc-tests

Fork of seldridge/rocket-rocc-examples with tests for a systolic array based matmul accelerator
C
48
star
24

chisel-gui

A prototype GUI for chisel-development
Scala
45
star
25

berkeley-testfloat-3

TestFloat release 3
C
42
star
26

hwacha-template

Template for projects using the Hwacha data-parallel accelerator
C
33
star
27

barstools

Useful utilities for BAR projects
Scala
31
star
28

RoSE

A unified simulation platform that combines hardware and software, enabling pre-silicon, full-stack, closed-loop evaluation of your robotic system.
Python
30
star
29

autophase

Python
27
star
30

cva6-wrapper

Wrapper for ETH Ariane Core
Scala
20
star
31

riscv-benchmarks

C
18
star
32

riscv-blas

Custom BLAS and LAPACK Cross-Compilation Framework for RISC-V
Fortran
17
star
33

nvdla-wrapper

Wraps the NVDLA project for Chipyard integration
Verilog
17
star
34

MoCA

Scala
17
star
35

libgloss-htif

A libgloss replacement for RISC-V that supports HTIF
C
16
star
36

esp-isa-sim

Custom extensions to the RISC-V isa simulator for the UCB-BAR ESP project
C
16
star
37

asyncqueue

Lightweight re-packaging of AsyncQueue library from rocket-chip
Scala
15
star
38

fpga-spartan6

Support for zScale on Spartan6 FPGAs
Verilog
15
star
39

shuttle

A Rocket-based RISC-V superscalar in-order core
Scala
13
star
40

chisel-awl

Scala
13
star
41

protoacc

Scala
11
star
42

midas-examples

Simple MIDAS Examples
Scala
10
star
43

firrtl-transform-tutorial

A template for developing custom FIRRTL transforms
Scala
10
star
44

vaesa

Learning A Continuous and Reconstructible Latent Space for Hardware Accelerator Design
Python
9
star
45

esp-tools

Shell
9
star
46

hammer-cadence-plugins

Hammer plugins for Cadence tools
Python
9
star
47

fpga-images-zedboard

prebuilt images for zedboard zynq fpga
9
star
48

context-dependent-environments

A Scala library for Context-Dependent Evironments
Scala
9
star
49

firrtl-uclid

Scala
8
star
50

chisel-sift

Scala
8
star
51

hammer-synopsys-plugins

Hammer plugins for synopsys tools
Python
8
star
52

rocket-dsp-utils

Tools for integrating DspTools components into a rocket-chip
Scala
8
star
53

midas-release

MIDAS Public Release
Scala
8
star
54

midas-top-release

MIDAS RocketChip Template
Scala
7
star
55

riscv-docker-images

Curated set of DockerFiles for RISC-V projects
Dockerfile
7
star
56

FFTGenerator

Scala
7
star
57

plsi-mdf

Macro description format
Scala
7
star
58

spec2017-workload

FireMarshal workload for SPEC2017
Python
7
star
59

midas-zynq

A zynq host-platform shell for midas generated simulators.
Tcl
7
star
60

maltese-smt

Archived! All relevant features are now part of the firrtl smt backend or the chiseltest library.
Scala
7
star
61

nvdla-workload

Base NVDLA Workload for FireMarshal
Shell
5
star
62

hwacha-net

C
5
star
63

dosa

DOSA: Differentiable Model-Based One-Loop Search for DNN Accelerators
Python
5
star
64

compress-acc

Scala
5
star
65

fixedpoint

Chisel Fixed-Point Arithmetic Library
Scala
5
star
66

esp-tests

Custom extensions to the RISC-V tests for the UCB-BAR ESP project
C
5
star
67

chipyard-toolchain-prebuilt

Pre-built riscv-gnu-toolchain binaries. You should most likely only shallow clone this.
Makefile
4
star
68

pwm-chisel-example

pwm-chisel-example for risc-v summer 2016 workshop
Scala
4
star
69

cs152-lab4

CS152 Lab 4
C
4
star
70

riscv-tools-feedstock

Shell
4
star
71

stac-top

The SRAM timing analysis chip for verifying SRAMs generated by SRAM22
Scala
3
star
72

opencl-kernels

OpenCL kernels for ucb-bar hardware
C
3
star
73

bits

Firebox Benchmarks
Python
3
star
74

chipper-tutorial

tutorial for chipper
C++
3
star
75

coremark-workload

FireMarshal workload for CoreMark EEMBC
Shell
3
star
76

spike-devices

Collection of device models for spike
C++
3
star
77

2023-winter-demo-project-power-aka-bora

Python
3
star
78

rerocc

Scala
3
star
79

vcd2step

Converts a VCD file to a Chisel tester input file
C++
2
star
80

pocl

C
2
star
81

firrtl2

UC Berkeley Copy of the FIRRTL Compiler
Scala
2
star
82

chisel-torture

A tool that generates Chisel torture tests
C++
2
star
83

fpga-images-zybo

2
star
84

ibex-wrapper

Wrapper for lowRISC Ibex
Scala
2
star
85

bar-fetchers

Berkeley Architecture Research pre-Fetchers
Scala
2
star
86

lbnl-torch

LBNL TORCH Reference Kernels
C
2
star
87

chisel-library-template

Use for developing Chisel+Firrtl libraries
2
star
88

Baremetal-IDE

A submodule of Chipyard https://github.com/ucb-bar/chipyard
HTML
2
star
89

fpga-images-zc706

2
star
90

caliptra-aes-acc

SystemVerilog
2
star
91

testers-regression

Uses gcd to do some really basic speed comparisons
Scala
1
star
92

esp-test-env

Custom extensions to the RISC-V test environments for the UCB-BAR ESP project
C
1
star
93

chisel-release

Chisel release tooling
1
star
94

sha3-workload

FireMarshal workload for the sha3 example rocc accelerator
C
1
star
95

esp-tools-feedstock

Shell
1
star
96

stac-bringup

Bringup infrastructure for the SRAM Timing Analysis Chip
C
1
star
97

esp-opcodes

Custom extensions to the RISC-V opcodes for the UCB-BAR ESP project
TeX
1
star
98

esp-gnu-toolchain

Custom extensions to the RISC-V toolchain for the UCB-BAR ESP project
C
1
star
99

Baremetal-llama

C
1
star
100

tsi

Standalone tethered serial interface (TSI) implementation with CLI utilities.
Rust
1
star