Skip to content

Commit

Permalink
Add no-plugin-tests for testing Chisel without the compiler plugin
Browse files Browse the repository at this point in the history
This is a new SBT build unit that symlinks in some files from the normal
chisel project tests, but builds them without the compiler plugin.
  • Loading branch information
jackkoenig committed Feb 10, 2021
1 parent 2ed343e commit 53b6204
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
if: matrix.scala == '2.12.13'
run: sbt ++${{ matrix.scala }} docs/mdoc
- name: Test
run: sbt ++${{ matrix.scala }} test
run: sbt ++${{ matrix.scala }} test noPluginTests/test
- name: Binary compatibility
run: sbt ++${{ matrix.scala }} mimaReportBinaryIssues

Expand Down
5 changes: 5 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ lazy val chisel = (project in file(".")).
)
)

lazy val noPluginTests = (project in file ("no-plugin-tests")).
dependsOn(chisel).
settings(commonSettings: _*).
settings(chiselSettings: _*)

lazy val docs = project // new documentation project
.in(file("docs-target")) // important: it must not be docs/
.dependsOn(chisel)
Expand Down
56 changes: 1 addition & 55 deletions src/test/scala/chiselTests/ChiselSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -90,62 +90,8 @@ trait ChiselRunners extends Assertions with BackendCompilationUtilities {
/** Spec base class for BDD-style testers. */
abstract class ChiselFlatSpec extends AnyFlatSpec with ChiselRunners with Matchers

class ChiselTestUtilitiesSpec extends ChiselFlatSpec {
import org.scalatest.exceptions.TestFailedException
// Who tests the testers?
"assertKnownWidth" should "error when the expected width is wrong" in {
val caught = intercept[ChiselException] {
assertKnownWidth(7) {
Wire(UInt(8.W))
}
}
assert(caught.getCause.isInstanceOf[TestFailedException])
}

it should "error when the width is unknown" in {
a [ChiselException] shouldBe thrownBy {
assertKnownWidth(7) {
Wire(UInt())
}
}
}

it should "work if the width is correct" in {
assertKnownWidth(8) {
Wire(UInt(8.W))
}
}

"assertInferredWidth" should "error if the width is known" in {
val caught = intercept[ChiselException] {
assertInferredWidth(8) {
Wire(UInt(8.W))
}
}
assert(caught.getCause.isInstanceOf[TestFailedException])
}

it should "error if the expected width is wrong" in {
a [TestFailedException] shouldBe thrownBy {
assertInferredWidth(8) {
val w = Wire(UInt())
w := 2.U(2.W)
w
}
}
}

it should "pass if the width is correct" in {
assertInferredWidth(4) {
val w = Wire(UInt())
w := 2.U(4.W)
w
}
}
}

/** Spec base class for property-based testers. */
class ChiselPropSpec extends PropSpec with ChiselRunners with ScalaCheckPropertyChecks with Matchers {
abstract class ChiselPropSpec extends PropSpec with ChiselRunners with ScalaCheckPropertyChecks with Matchers {

// Constrain the default number of instances generated for every use of forAll.
implicit override val generatorDrivenConfig: PropertyCheckConfiguration =
Expand Down
60 changes: 60 additions & 0 deletions src/test/scala/chiselTests/ChiselTestUtilitiesSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: Apache-2.0

package chiselTests

import chisel3._
import org.scalatest.exceptions.TestFailedException

class ChiselTestUtilitiesSpec extends ChiselFlatSpec {
// Who tests the testers?
"assertKnownWidth" should "error when the expected width is wrong" in {
val caught = intercept[ChiselException] {
assertKnownWidth(7) {
Wire(UInt(8.W))
}
}
assert(caught.getCause.isInstanceOf[TestFailedException])
}

it should "error when the width is unknown" in {
a [ChiselException] shouldBe thrownBy {
assertKnownWidth(7) {
Wire(UInt())
}
}
}

it should "work if the width is correct" in {
assertKnownWidth(8) {
Wire(UInt(8.W))
}
}

"assertInferredWidth" should "error if the width is known" in {
val caught = intercept[ChiselException] {
assertInferredWidth(8) {
Wire(UInt(8.W))
}
}
assert(caught.getCause.isInstanceOf[TestFailedException])
}

it should "error if the expected width is wrong" in {
a [TestFailedException] shouldBe thrownBy {
assertInferredWidth(8) {
val w = Wire(UInt())
w := 2.U(2.W)
w
}
}
}

it should "pass if the width is correct" in {
assertInferredWidth(4) {
val w = Wire(UInt())
w := 2.U(4.W)
w
}
}
}

0 comments on commit 53b6204

Please sign in to comment.