Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test for issue 4159 #4161

Merged
merged 2 commits into from
Jun 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/test/scala/chiselTests/ChiselEnum.scala
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,30 @@ class ChiselEnumSpec extends ChiselFlatSpec with Utils {
assertTesterPasses(new CastToUIntTester)
}

// This is a bug, but fixing it may break user code.
// See: https://github.com/chipsalliance/chisel/issues/4159
it should "preserve legacy width behavior" in {
val verilog = ChiselStage.emitSystemVerilog(new RawModule {
val out1, out2, out3 = IO(Output(UInt(8.W)))
val e = EnumExample.e1
val x = e.asUInt
val y = e.asTypeOf(UInt())
val z = e.asTypeOf(UInt(e.getWidth.W))
out1 := Cat(1.U, x)
out2 := Cat(1.U, y)
out3 := Cat(1.U, z)
// The bug is that the width of x is 7 but the value of out1 is 3
x.getWidth should be(7)
x.getWidth should be(EnumExample.getWidth)
y.widthOption should be(None)
z.getWidth should be(7)
})
// The bug is that all of these should be the same as out3, or the widths above are wrong
verilog should include("assign out1 = 8'h3;")
verilog should include("assign out2 = 8'h3;")
verilog should include("assign out3 = 8'h81;")
}
Copy link
Member

Choose a reason for hiding this comment

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

Scalatest doesn't have XFAIL, right? This would be better as that if it's supported. Alternatively, this could be a should not include which is the correct thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think ScalaTest has an XFAIL per se, more of should not include yeah. Are you suggesting I also add should not for the "correct" output when we fix this (ie. verilog should not include("assign out1 = 8'h81;") and verilog should not include("assign out2 = 8'h81;"))? Or are you suggesting something else?


it should "cast literal UInts to enums correctly" in {
assertTesterPasses(new CastFromLitTester)
}
Expand Down