-
Notifications
You must be signed in to change notification settings - Fork 303
Working on porting bootcamp to chiseltest #121
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
Changes from all commits
827a43c
841e01d
c4b5213
d17d599
407896f
0840b4c
8afaa4e
a0671e0
ac87f5c
89b4197
3934d61
580e825
6ae3c55
fd226b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,10 +31,8 @@ | |
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "collapsed": false | ||
| }, | ||
| cleaclear "execution_count": null, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "val path = System.getProperty(\"user.dir\") + \"/source/load-ivy.sc\"\n", | ||
|
|
@@ -51,14 +49,14 @@ | |
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "collapsed": false | ||
| }, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "import chisel3._\n", | ||
| "import chisel3.util._\n", | ||
| "import chisel3.iotesters.{ChiselFlatSpec, Driver, PeekPokeTester}" | ||
| "import chisel3.tester._\n", | ||
| "import chisel3.tester.RawTester.test\n", | ||
| "import dotvisualizer._" | ||
| ] | ||
| }, | ||
| { | ||
|
|
@@ -76,9 +74,7 @@ | |
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "collapsed": false | ||
| }, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "// Chisel Code: Declare a new module definition\n", | ||
|
|
@@ -131,9 +127,7 @@ | |
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "collapsed": false | ||
| }, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "// Scala Code: Elaborate our Chisel design by translating it to Verilog\n", | ||
|
|
@@ -154,9 +148,7 @@ | |
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "collapsed": false | ||
| }, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "// Chisel Code, but pass in a parameter to set widths of ports\n", | ||
|
|
@@ -200,26 +192,26 @@ | |
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "collapsed": false | ||
| }, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "// Scala Code: Calling Driver to instantiate Passthrough + PeekPokeTester and execute the test.\n", | ||
| "// Don't worry about understanding this code; it is very complicated Scala.\n", | ||
| "// Think of it more as boilerplate to run a Chisel test.\n", | ||
| "val testResult = Driver(() => new Passthrough()) {\n", | ||
| " c => new PeekPokeTester(c) {\n", | ||
| " poke(c.io.in, 0) // Set our input to value 0\n", | ||
| " expect(c.io.out, 0) // Assert that the output correctly has 0\n", | ||
| " poke(c.io.in, 1) // Set our input to value 1\n", | ||
| " expect(c.io.out, 1) // Assert that the output correctly has 1\n", | ||
| " poke(c.io.in, 2) // Set our input to value 2\n", | ||
| " expect(c.io.out, 2) // Assert that the output correctly has 2\n", | ||
| " }\n", | ||
| "test(new Passthrough()) { c =>\n", | ||
| " c.io.in.poke(0.U) // Set our input to value 0\n", | ||
| " c.io.out.expect(0.U) // Assert that the output correctly has 0\n", | ||
| " c.io.in.poke(1.U) // Set our input to value 1\n", | ||
| " c.io.out.expect(1.U) // Assert that the output correctly has 1\n", | ||
| " c.io.in.poke(2.U) // Set our input to value 2\n", | ||
| " c.io.out.expect(2.U) // Assert that the output correctly has 2\n", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have an example anywhere of an |
||
| "}\n", | ||
| "assert(testResult) // Scala Code: if testResult == false, will throw an error\n", | ||
| "println(\"SUCCESS!!\") // Scala Code: if we get here, our tests passed!" | ||
| "println(\"SUCCESS!!\") // Scala Code: if we get here, our tests passed!\n", | ||
| "\n", | ||
| "(new stage.DiagrammerStage).execute(\n", | ||
| " Array(\"--target-dir\", \"diagrams\"),\n", | ||
| " Seq(chisel3.stage.ChiselGeneratorAnnotation(() => new Passthrough()))\n", | ||
| ")" | ||
| ] | ||
| }, | ||
| { | ||
|
|
@@ -228,7 +220,11 @@ | |
| "source": [ | ||
| "What's going on? The test accepts a `Passthrough` module, assigns values to the module's inputs, and checks its outputs. To set an input, we call `poke`. To check an output, we call `expect`. If we don't want to compare the output to an expected value (no assertion), we can `peek` the output instead.\n", | ||
| "\n", | ||
| "If all `expect` statements are true, then our boilerplate code will return true (see `testResult`)." | ||
| "If all `expect` statements are true, then our boilerplate code will return pass.\n", | ||
| "\n", | ||
| ">Note that the `poke` and `expect` use chisel hardware literal notation. Both operations expect literals of the correct type.\n", | ||
| "If `poke`ing a `UInt()` you must supply a `UInt` literal (example: `c.io.in.poke(10.U)`, likewise if the input is a `Bool()` the `poke` would expect either `true.B` or `false.B`.\n", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might also be useful to provide a negative example for each, eg for UInt, "this is distinct from a Scala number, eg |
||
| "\n" | ||
| ] | ||
| }, | ||
| { | ||
|
|
@@ -242,16 +238,27 @@ | |
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "collapsed": true | ||
| }, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "val test10result = ???\n", | ||
| "// Test with width 10\n", | ||
| "\n", | ||
| "// Test with width 20\n", | ||
| "\n", | ||
| "val test20result = ???\n", | ||
| "test(new PassthroughGenerator(10)) { c =>\n", | ||
| " c.io.in.poke(0.U)\n", | ||
| " c.io.out.expect(0.U)\n", | ||
| " c.io.in.poke(1023.U)\n", | ||
| " c.io.out.expect(1023.U)\n", | ||
| "}\n", | ||
| "\n", | ||
| "test(new PassthroughGenerator(20)) { c =>\n", | ||
| " c.io.in.poke(0.U)\n", | ||
| " c.io.out.expect(0.U)\n", | ||
| " c.io.in.poke(1048575.U)\n", | ||
| " c.io.out.expect(1048575.U)\n", | ||
| "}\n", | ||
| "\n", | ||
| "assert((test10result == true) && (test20result == true))\n", | ||
| "println(\"SUCCESS!!\") // Scala Code: if we get here, our tests passed!" | ||
| ] | ||
| }, | ||
|
|
@@ -264,22 +271,18 @@ | |
| "<label for=\"check-1\"><strong>Solution</strong> (click to toggle displaying it)</label>\n", | ||
| "<article>\n", | ||
| "<pre style=\"background-color:#f7f7f7\">\n", | ||
| "val test10result = Driver(() => new PassthroughGenerator(10)) {\n", | ||
| " c => new PeekPokeTester(c) {\n", | ||
| " poke(c.io.in, 0)\n", | ||
| " expect(c.io.out, 0)\n", | ||
| " poke(c.io.in, 1023)\n", | ||
| " expect(c.io.out, 1023)\n", | ||
| " }\n", | ||
| "test(new PassthroughGenerator(10)) { c =>\n", | ||
| " c.io.in.poke(0.U)\n", | ||
| " c.io.out.expect(0.U)\n", | ||
| " c.io.in.poke(1023.U)\n", | ||
| " c.io.out.expect(1023.U)\n", | ||
| "}\n", | ||
| "\n", | ||
| "val test20result = Driver(() => new PassthroughGenerator(20)) {\n", | ||
| " c => new PeekPokeTester(c) {\n", | ||
| " poke(c.io.in, 0)\n", | ||
| " expect(c.io.out, 0)\n", | ||
| " poke(c.io.in, 1048575)\n", | ||
| " expect(c.io.out, 1048575)\n", | ||
| " }\n", | ||
| "test(new PassthroughGenerator(20)) { c =>\n", | ||
| " c.io.in.poke(0.U)\n", | ||
| " c.io.out.expect(0.U)\n", | ||
| " c.io.in.poke(1048575.U)\n", | ||
| " c.io.out.expect(1048575.U)\n", | ||
| "}\n", | ||
| "\n", | ||
| "</pre></article></div></section></div>" | ||
|
|
@@ -300,9 +303,7 @@ | |
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "collapsed": true | ||
| }, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "// Viewing the Verilog for debugging\n", | ||
|
|
@@ -312,9 +313,7 @@ | |
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "collapsed": true | ||
| }, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "// Viewing the firrtl for debugging\n", | ||
|
|
@@ -352,9 +351,7 @@ | |
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "collapsed": true | ||
| }, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "class PrintingModule extends Module {\n", | ||
|
|
@@ -371,14 +368,20 @@ | |
| " println(s\"Print during generation: Input is ${io.in}\")\n", | ||
| "}\n", | ||
| "\n", | ||
| "class PrintingModuleTester(c: PrintingModule) extends PeekPokeTester(c) {\n", | ||
| " poke(c.io.in, 3)\n", | ||
| " step(5) // circuit will print\n", | ||
| "test(new PrintingModule ) { c =>\n", | ||
| " c.io.in.poke(3.U)\n", | ||
| " c.clock.step(5) // circuit will print\n", | ||
| " \n", | ||
| " println(s\"Print during testing: Input is ${peek(c.io.in)}\")\n", | ||
| "}\n", | ||
| "chisel3.iotesters.Driver( () => new PrintingModule ) { c => new PrintingModuleTester(c) }" | ||
| " println(s\"Print during testing: Input is ${c.io.in.peek()}\")\n", | ||
| "}" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [] | ||
| } | ||
| ], | ||
| "metadata": { | ||
|
|
@@ -394,7 +397,7 @@ | |
| "mimetype": "text/x-scala", | ||
| "name": "scala", | ||
| "nbconvert_exporter": "script", | ||
| "version": "2.12.8" | ||
| "version": "2.12.10" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment can go away now because of
testmagic