Skip to content

Conversation

seldridge
Copy link
Member

@seldridge seldridge commented Feb 27, 2025

Add an extension-method based FileCheck API. This builds off of @jackkoenig's original FileCheck trait inside ChiselSpec and repackages it for publishing.

This makes a number of deviations from the original version:

  1. This opts for extension methods.
  2. This does not add helpers for running Chisel.
  3. This throws dedicated assertions on failures.

Taking (1) and (2) together, this is intended to not duplicate methods which are already availble via ChiselStage. Specifically, I am intending the API to be used like:

ChiselStage.emitSystemVerilgo(new Foo).fileCheck()("CHECK: module Foo")

Things are done this way to try to make the APIs as orthogonal as possible without too many redundant ways to accomplish the same thing.

(3): is added for convenience of testing. On failure, this provides an output that approximates what you get from lit (LLVM's Integrated Tester). This additionally provides a rerun script that you can just copy-paste into a terminal to reproduce the failure.

For ease of reproduction, both the input and the check are written to files with predictable names in a temporary directory underneath what is provided by an implementation of the HasTestingDirectory type class. Having both the input and check file are necessary to do easy reruns.

This is stacked on #4750.

Release Notes

Add chisel3.testing.FileCheck and chisel3.testing.scalatest.FileCheck trait for writing FileCheck-based tests. This is useful for testing generators where you want to examine the output (FIRRTL or Verilog) as opposed to run a simulation. This is intended to complement ChiselSim.

@seldridge seldridge requested a review from jackkoenig February 27, 2025 23:55
@seldridge seldridge added the Feature New feature, will be included in release notes label Feb 27, 2025
@seldridge seldridge force-pushed the dev/seldridge/move-FileCheck-into-testing branch from 1ade6ea to 5632c56 Compare February 28, 2025 02:18
Base automatically changed from dev/seldridge/factor-HasTestingDirectory-out-of-simulator-and-into-testing to main February 28, 2025 02:37
Add an extension-method based FileCheck API.  This builds off of
@jackkoenig's original FileCheck trait inside ChiselSpec and repackages it
for publishing.

This makes a number of deviations from the original version:

  1. This opts for extension methods.
  2. This does not add helpers for running Chisel.
  3. This throws dedicated assertions on failures.

Taking (1) and (2) together, this is intended to _not_ duplicate methods
which are already availble via ChiselStage.  Specifically, I am intending
the API to be used like:

    ChiselStage.emitSystemVerilgo(new Foo).fileCheck()("CHECK: module Foo")

Things are done this way to try to make the APIs as orthogonal as possible
without too many redundant ways to accomplish the same thing.

(3): is added for convenience of testing.  On failure, this provides an
output that approximates what you get from lit (LLVM's Integrated Tester).
This additionally provides a rerun script that you can just copy-paste
into a terminal to reproduce the failure.

For ease of reproduction, both the input and the check are written to
files with predictable names in a temporary directory underneath what is
provided by an implementation of the `HasTestingDirectory` type class.
Having both the input and check file are necessary to do easy reruns.

Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
@seldridge seldridge force-pushed the dev/seldridge/move-FileCheck-into-testing branch from 5632c56 to d5635e4 Compare February 28, 2025 02:45
Copy link
Contributor

@jackkoenig jackkoenig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really slick!

@seldridge seldridge merged commit 347bd06 into main Feb 28, 2025
15 checks passed
@seldridge seldridge deleted the dev/seldridge/move-FileCheck-into-testing branch February 28, 2025 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature, will be included in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants