• This repository has been archived on 19/Aug/2024
  • Stars
    star
    220
  • Rank 180,422 (Top 4 %)
  • Language
    Scala
  • License
    Other
  • Created about 6 years ago
  • Updated 3 months 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,601
star
2

gemmini

Berkeley's Spatial Array Generator
Scala
793
star
3

riscv-sodor

educational microarchitectures for risc-v isa
Scala
673
star
4

chisel-tutorial

chisel tutorial exercises and answers
Scala
643
star
5

riscv-mini

Simple RISC-V 3-stage Pipeline in Chisel
Scala
538
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
253
star
10

dsptools

A Library of Chisel3 Tools for Digital Signal Processing
Scala
219
star
11

berkeley-softfloat-3

SoftFloat release 3
C
217
star
12

constellation

A Chisel RTL generator for network-on-chip interconnects
Scala
174
star
13

riscv-torture

RISC-V Torture Test
Scala
163
star
14

hwacha

Microarchitecture implementation of the decoupled vector-fetch accelerator
Scala
146
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
96
star
17

testchipip

Scala
80
star
18

onnxruntime-riscv

Fork of upstream onnxruntime focused on supporting risc-v accelerators
C++
79
star
19

sha3

Verilog
76
star
20

cosa

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

ccbench

Memory System Microbenchmarks
C
57
star
22

gemmini-rocc-tests

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

zscale

Z-scale Microarchitectural Implementation of RV32 ISA
C
53
star
24

chisel-gui

A prototype GUI for chisel-development
Scala
49
star
25

berkeley-testfloat-3

TestFloat release 3
C
46
star
26

hwacha-template

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

RoSE

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

barstools

Useful utilities for BAR projects
Scala
31
star
29

autophase

Python
28
star
30

shuttle

A Rocket-based RISC-V superscalar in-order core
Scala
26
star
31

riscv-benchmarks

C
22
star
32

MoCA

Scala
22
star
33

saturn-vectors

Chisel RISC-V Vector 1.0 Implementation
Assembly
22
star
34

libgloss-htif

A libgloss replacement for RISC-V that supports HTIF
C
21
star
35

nvdla-wrapper

Wraps the NVDLA project for Chipyard integration
Verilog
20
star
36

cva6-wrapper

Wrapper for ETH Ariane Core
Scala
20
star
37

esp-isa-sim

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

asyncqueue

Lightweight re-packaging of AsyncQueue library from rocket-chip
Scala
17
star
39

riscv-blas

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

fpga-spartan6

Support for zScale on Spartan6 FPGAs
Verilog
15
star
41

chisel-awl

Scala
13
star
42

dosa

DOSA: Differentiable Model-Based One-Loop Search for DNN Accelerators
Python
13
star
43

Baremetal-NN

A tool for converting PyTorch models into raw C codes that can be executed standalone in a baremetal runtime on RISC-V research chips.
C
12
star
44

rocket-dsp-utils

Tools for integrating DspTools components into a rocket-chip
Scala
11
star
45

protoacc

Scala
11
star
46

midas-examples

Simple MIDAS Examples
Scala
10
star
47

vaesa

Learning A Continuous and Reconstructible Latent Space for Hardware Accelerator Design
Python
10
star
48

firrtl-transform-tutorial

A template for developing custom FIRRTL transforms
Scala
10
star
49

hammer-cadence-plugins

Hammer plugins for Cadence tools
Python
10
star
50

FFTGenerator

Scala
9
star
51

esp-tools

Shell
9
star
52

fpga-images-zedboard

prebuilt images for zedboard zynq fpga
9
star
53

compress-acc

Scala
9
star
54

context-dependent-environments

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

firrtl-uclid

Scala
8
star
56

plsi-mdf

Macro description format
Scala
8
star
57

chisel-sift

Scala
8
star
58

hammer-synopsys-plugins

Hammer plugins for synopsys tools
Python
8
star
59

midas-release

MIDAS Public Release
Scala
8
star
60

fixedpoint

Chisel Fixed-Point Arithmetic Library
Scala
8
star
61

midas-top-release

MIDAS RocketChip Template
Scala
7
star
62

riscv-docker-images

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

spec2017-workload

FireMarshal workload for SPEC2017
Python
7
star
64

midas-zynq

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

spike-devices

Collection of device models for spike
C++
7
star
66

rerocc

Scala
7
star
67

Baremetal-IDE

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

maltese-smt

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

esp-tests

Custom extensions to the RISC-V tests for the UCB-BAR ESP project
C
6
star
70

nvdla-workload

Base NVDLA Workload for FireMarshal
Shell
5
star
71

hwacha-net

C
5
star
72

firrtl2

UC Berkeley Copy of the FIRRTL Compiler
Scala
5
star
73

AuRORA

Virtualized Accelerator Orchestration for Multi-Tenant Workloads
C
5
star
74

pyuartsi

A standalone implementation of the Tethered Serial Interface (TSI) in Python.
Python
5
star
75

chipyard-toolchain-prebuilt

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

pwm-chisel-example

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

cs152-lab4

CS152 Lab 4
C
4
star
78

ibex-wrapper

Wrapper for lowRISC Ibex
Scala
4
star
79

riscv-tools-feedstock

Shell
4
star
80

stac-top

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

opencl-kernels

OpenCL kernels for ucb-bar hardware
C
3
star
82

chipper-tutorial

tutorial for chipper
C++
3
star
83

coremark-workload

FireMarshal workload for CoreMark EEMBC
Shell
3
star
84

bits

Firebox Benchmarks
Python
3
star
85

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

Python
3
star
86

Baremetal-llama

C
3
star
87

chipyard-cs152-sp24

C
3
star
88

riscv-coremark-pro

Compiles coremark-pro for riscv64 baremetal
Makefile
3
star
89

vcd2step

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

pocl

C
2
star
91

chisel-release

Chisel release tooling
2
star
92

chisel-torture

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

fpga-images-zybo

2
star
94

ara-wrapper

Scala
2
star
95

bar-fetchers

Berkeley Architecture Research pre-Fetchers
Scala
2
star
96

lbnl-torch

LBNL TORCH Reference Kernels
C
2
star
97

chisel-library-template

Use for developing Chisel+Firrtl libraries
2
star
98

fpga-images-zc706

2
star
99

baseband-modem

Digital baseband-modem processor for 2.4 GHz Bluetooth Low Energy and IEEE 802.15.4 standards
Jupyter Notebook
2
star
100

caliptra-aes-acc

SystemVerilog
2
star