From 7e5aef460e089b3dfd53ddd181f9384cc25145d7 Mon Sep 17 00:00:00 2001 From: jackkoenig Date: Tue, 20 Sep 2016 16:12:59 -0700 Subject: Add Cookbook tests These tests are intended to be the examples in the Chisel3 Wiki Cookbook. --- src/test/scala/cookbook/Bundle2UInt.scala | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/test/scala/cookbook/Bundle2UInt.scala (limited to 'src/test/scala/cookbook/Bundle2UInt.scala') diff --git a/src/test/scala/cookbook/Bundle2UInt.scala b/src/test/scala/cookbook/Bundle2UInt.scala new file mode 100644 index 00000000..d74218a8 --- /dev/null +++ b/src/test/scala/cookbook/Bundle2UInt.scala @@ -0,0 +1,31 @@ +// See LICENSE for license details. + +package cookbook + +import chisel3._ + +/* ### How do I create a UInt from an instance of a Bundle? + * + * Call asUInt on the Bundle instance + */ +class Bundle2UInt extends CookbookTester(0) { + // Example + class MyBundle extends Bundle { + val foo = UInt(width = 4) + val bar = UInt(width = 4) + } + val bundle = Wire(new MyBundle) + bundle.foo := UInt(0xc) + bundle.bar := UInt(0x3) + val uint = bundle.asUInt + printf(p"$uint") // 195 + + // Test + assert(uint === UInt(0xc3)) +} + +class Bundle2UIntSpec extends CookbookSpec { + "Bundle2UInt" should "work" in { + assertTesterPasses { new Bundle2UInt } + } +} -- cgit v1.2.3