-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a913040
commit debfd43
Showing
16 changed files
with
263 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -745,3 +745,5 @@ $RECYCLE.BIN/ | |
*.fir | ||
*.v | ||
target | ||
.dccache | ||
*.thex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
integration_test: | ||
python3 ./scripts/integration_test/run.py | ||
clean: | ||
python3 ./scripts/integration_test/clean.py | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from pathlib import Path | ||
import sys | ||
from jinja2 import Environment, PackageLoader, select_autoescape | ||
|
||
|
||
def intToBin32(i): | ||
return int((bin(((1 << 32) - 1) & i)[2:]).zfill(32), 2) | ||
|
||
def render_program_rom(expected): | ||
env = Environment( | ||
loader=PackageLoader("checker", "templates"), | ||
autoescape=select_autoescape() | ||
) | ||
template = env.get_template("TopTest.scala.template") | ||
content = template.render(expected=expected) | ||
print(content) | ||
|
||
|
||
def main(): | ||
expected_file = Path(sys.argv[1]) | ||
expected = [] | ||
with expected_file.open('r') as f: | ||
for line in (line.strip() for line in f if line.strip() != ""): | ||
expected.append(intToBin32(int(line))) | ||
render_program_rom(expected) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import os | ||
import shutil | ||
|
||
|
||
shutil.copyfile("./src/main/scala/ProgramROM.scala.backup", | ||
"./src/main/scala/ProgramROM.scala") | ||
shutil.copyfile("./src/test/scala/TopTest.scala.backup", | ||
"./src/test/scala/TopTest.scala") | ||
os.remove("./src/main/scala/ProgramROM.scala.backup") | ||
os.remove("./src/test/scala/TopTest.scala.backup") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import sys | ||
from pathlib import Path | ||
|
||
from jinja2 import Environment, PackageLoader, select_autoescape | ||
|
||
|
||
def render_program_rom(address_table, code_table): | ||
env = Environment( | ||
loader=PackageLoader("rom", "templates"), | ||
autoescape=select_autoescape() | ||
) | ||
template = env.get_template("ProgramROM.scala.template") | ||
content = template.render( | ||
address_table=address_table, code_table=code_table) | ||
print(content) | ||
|
||
|
||
def main(): | ||
lot_file = Path(sys.argv[1]) | ||
address_table = {} | ||
with lot_file.open('r') as f: | ||
for line in (l.strip() for l in f.readlines() if l.strip() != ""): | ||
[section_name, section_address] = line.split(":") | ||
section_address = int(section_address, 16) | ||
address_table[section_name] = section_address | ||
code_table = {} | ||
for section in address_table.keys(): | ||
path = lot_file.parent.joinpath('{}.thex'.format(section)) | ||
with path.open('r') as f: | ||
code_table[section] = [l.strip() | ||
for l in f.readlines() if l.strip() != ""] | ||
render_program_rom(address_table, code_table) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import glob | ||
import os | ||
from pathlib import Path | ||
import shutil | ||
import sys | ||
|
||
shutil.copyfile("./src/main/scala/ProgramROM.scala", | ||
"./src/main/scala/ProgramROM.scala.backup") | ||
shutil.copyfile("./src/test/scala/TopTest.scala", "./src/test/scala/TopTest.scala.backup") | ||
fail = False | ||
for filenamestr in glob.glob('test_cases/*'): | ||
filename = Path(filenamestr) | ||
for asmstr in glob.glob(filenamestr + '/*.asm'): | ||
asm = Path(asmstr) | ||
os.system( | ||
"docker run -i shuosc/shuasm < {} > {}" | ||
.format(asmstr, asm.parent.joinpath("{}.thex".format(asm.stem))) | ||
) | ||
rom = os.popen( | ||
"python3 ./scripts/integration_test/rom.py ./{}/layout.lot" | ||
.format(filename) | ||
).read() | ||
expected = os.popen( | ||
"python3 ./scripts/integration_test/checker.py ./{}/expected.exp" | ||
.format(filename) | ||
).read() | ||
with open('./src/main/scala/ProgramROM.scala', 'w') as f: | ||
f.write(rom) | ||
with open('./src/test/scala/TopTest.scala', 'w') as f: | ||
f.write(expected) | ||
return_value = os.system('sbt "testOnly TopSpec" > /dev/null') | ||
if return_value & 0xff00 != 0: | ||
print("Test failed: {}".format(filename)) | ||
fail = True | ||
break | ||
|
||
shutil.copyfile("./src/main/scala/ProgramROM.scala.backup", | ||
"./src/main/scala/ProgramROM.scala") | ||
shutil.copyfile("./src/test/scala/TopTest.scala.backup", | ||
"./src/test/scala/TopTest.scala") | ||
os.remove("./src/main/scala/ProgramROM.scala.backup") | ||
os.remove("./src/test/scala/TopTest.scala.backup") | ||
if fail: | ||
sys.exit(1) |
23 changes: 23 additions & 0 deletions
23
scripts/integration_test/templates/ProgramROM.scala.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import chisel3._ | ||
|
||
class ProgramROMBundle extends Bundle { | ||
val address = Input(UInt(32.W)) | ||
val value = Output(UInt(32.W)) | ||
} | ||
|
||
// A temporary program ROM | ||
// Just for testing, use a real flash rom in real world | ||
class ProgramROM extends Module { | ||
val io = IO(new ProgramROMBundle) | ||
{% for section_name, section_content in code_table.items() %} | ||
val {{section_name}}Content = VecInit(Array( | ||
{% for instruction in section_content %}"h{{instruction}}".U(32.W), | ||
{% endfor %} | ||
)){% endfor %} | ||
{% for section_name, section_start in address_table.items() | sort(attribute='1')%} | ||
{% if loop.first %}when(io.address < "h{{"{:x}".format(section_start + 4*(code_table[section_name] | length))}}".U){% else %}.elsewhen(io.address < "h{{"{}".format(section_start + 4*(code_table[section_name] | length))}}".U){% endif %} { | ||
io.value := {{section_name}}Content((io.address - "h80000000".U) (31, 2)) | ||
}{% endfor %}.otherwise { | ||
io.value := 0xdead.U | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import chisel3._ | ||
import chisel3.iotesters._ | ||
import org.scalatest.{FlatSpec, Matchers} | ||
|
||
class TopTest(top: Top) extends PeekPokeTester(top) { | ||
var expected = List( | ||
{% for e in expected %}BigInt("{{e}}"), | ||
{% endfor %} | ||
) | ||
var last = BigInt(0) | ||
var countDown = 65536 | ||
while (!expected.isEmpty) { | ||
val next = peek(top.io.gpio) | ||
if (next != last) { | ||
expect(top.io.gpio, expected.head) | ||
expected = expected.tail | ||
countDown = 65536 | ||
} else { | ||
countDown -= 1 | ||
if (countDown <= 0) { | ||
fail | ||
expected = List() | ||
} | ||
} | ||
last = next | ||
step(1) | ||
} | ||
} | ||
|
||
class TopSpec extends FlatSpec with Matchers { | ||
behavior of "TopSpec" | ||
|
||
it should "compute successfully" in { | ||
chisel3.iotesters.Driver.execute(Array("--generate-vcd-output", "on"), () => new Top) { top => | ||
new TopTest(top) | ||
} should be(true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
main: | ||
li a0, 0x10012000 | ||
sw zero, 0(a0) | ||
li a2, 1 | ||
li a3, 2 | ||
add a2, a2, a3 | ||
sw a2, 0(a0) | ||
li a2, 3 | ||
li a3, 2 | ||
sub a2, a2, a3 | ||
sw a2, 0(a0) | ||
sub a2, a2, a3 | ||
sw a2, 0(a0) | ||
sll a2, a2, a3 | ||
sw a2, 0(a0) | ||
sra a2, a2, a3 | ||
addi a2, a2, 1 | ||
sw a2, 0(a0) | ||
addi a2, a2, -2 | ||
sw a2, 0(a0) | ||
slli a2, a2, 3 | ||
sw a2, 0(a0) | ||
srai a2, a2, 2 | ||
sw a2, 0(a0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
3 | ||
1 | ||
-1 | ||
-4 | ||
0 | ||
-2 | ||
-16 | ||
-4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
code: 0x80001000 |