-
Notifications
You must be signed in to change notification settings - Fork 58
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
Showing
8 changed files
with
298 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
TARGET=$(shell ls *.py | grep -v test | grep -v parsetab.py) | ||
ARGS= | ||
|
||
PYTHON=python3 | ||
#PYTHON=python | ||
#OPT=-m pdb | ||
#OPT=-m cProfile -s time | ||
#OPT=-m cProfile -o profile.rslt | ||
|
||
.PHONY: all | ||
all: test | ||
|
||
.PHONY: run | ||
run: | ||
$(PYTHON) $(OPT) $(TARGET) $(ARGS) | ||
|
||
.PHONY: test | ||
test: | ||
$(PYTHON) -m pytest -vv | ||
|
||
.PHONY: check | ||
check: | ||
$(PYTHON) $(OPT) $(TARGET) $(ARGS) > tmp.v | ||
iverilog -tnull -Wall tmp.v | ||
rm -f tmp.v | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf *.pyc __pycache__ parsetab.py .cache *.out *.png *.dot tmp.v uut.vcd |
18 changes: 18 additions & 0 deletions
18
tests/extension/thread_/stream_dump_mask/test_thread_stream_dump_mask.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,18 @@ | ||
from __future__ import absolute_import | ||
from __future__ import print_function | ||
|
||
import os | ||
import veriloggen | ||
import thread_stream_dump_mask | ||
|
||
|
||
def test(request): | ||
veriloggen.reset() | ||
|
||
simtype = request.config.getoption('--sim') | ||
|
||
rslt = thread_stream_dump_mask.run(filename=None, simtype=simtype, | ||
outputfile=os.path.splitext(os.path.basename(__file__))[0] + '.out') | ||
|
||
verify_rslt = rslt.splitlines()[-1] | ||
assert(verify_rslt == '# verify: PASSED') |
143 changes: 143 additions & 0 deletions
143
tests/extension/thread_/stream_dump_mask/thread_stream_dump_mask.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,143 @@ | ||
from __future__ import absolute_import | ||
from __future__ import print_function | ||
import sys | ||
import os | ||
|
||
# the next line can be removed after installation | ||
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname( | ||
os.path.dirname(os.path.dirname(os.path.abspath(__file__))))))) | ||
|
||
from veriloggen import * | ||
import veriloggen.thread as vthread | ||
import veriloggen.types.axi as axi | ||
|
||
|
||
def mkLed(): | ||
m = Module('blinkled') | ||
clk = m.Input('CLK') | ||
rst = m.Input('RST') | ||
|
||
datawidth = 32 | ||
addrwidth = 10 | ||
myaxi = vthread.AXIM(m, 'myaxi', clk, rst, datawidth) | ||
ram_a = vthread.RAM(m, 'ram_a', clk, rst, datawidth, addrwidth) | ||
ram_b = vthread.RAM(m, 'ram_b', clk, rst, datawidth, addrwidth) | ||
ram_c = vthread.RAM(m, 'ram_c', clk, rst, datawidth, addrwidth) | ||
|
||
strm = vthread.Stream(m, 'mystream', clk, rst, | ||
dump=True, dump_base=10, dump_mode='all') | ||
a = strm.source('a') | ||
b = strm.source('b') | ||
c = a + b | ||
strm.sink(c, 'c') | ||
|
||
def comp_stream(size, offset): | ||
strm.set_source('a', ram_a, offset, size) | ||
strm.set_source('b', ram_b, offset, size) | ||
strm.set_sink('c', ram_c, offset, size) | ||
strm.run() | ||
strm.join() | ||
strm.disable_dump() | ||
|
||
def comp_sequential(size, offset): | ||
sum = 0 | ||
for i in range(size): | ||
a = ram_a.read(i + offset) | ||
b = ram_b.read(i + offset) | ||
sum = a + b | ||
ram_c.write(i + offset, sum) | ||
|
||
def check(size, offset_stream, offset_seq): | ||
all_ok = True | ||
for i in range(size): | ||
st = ram_c.read(i + offset_stream) | ||
sq = ram_c.read(i + offset_seq) | ||
if vthread.verilog.NotEql(st, sq): | ||
all_ok = False | ||
if all_ok: | ||
print('# verify: PASSED') | ||
else: | ||
print('# verify: FAILED') | ||
|
||
def comp(size): | ||
# stream | ||
offset = 0 | ||
myaxi.dma_read(ram_a, offset, 0, size) | ||
myaxi.dma_read(ram_b, offset, 512, size) | ||
comp_stream(size, offset) | ||
comp_stream(size, offset) # dump disabled | ||
myaxi.dma_write(ram_c, offset, 1024, size) | ||
|
||
# sequential | ||
offset = size | ||
myaxi.dma_read(ram_a, offset, 0, size) | ||
myaxi.dma_read(ram_b, offset, 512, size) | ||
comp_sequential(size, offset) | ||
myaxi.dma_write(ram_c, offset, 1024 * 2, size) | ||
|
||
# verification | ||
check(size, 0, offset) | ||
|
||
vthread.finish() | ||
|
||
th = vthread.Thread(m, 'th_comp', clk, rst, comp) | ||
fsm = th.start(32) | ||
|
||
return m | ||
|
||
|
||
def mkTest(memimg_name=None): | ||
m = Module('test') | ||
|
||
# target instance | ||
led = mkLed() | ||
|
||
# copy paras and ports | ||
params = m.copy_params(led) | ||
ports = m.copy_sim_ports(led) | ||
|
||
clk = ports['CLK'] | ||
rst = ports['RST'] | ||
|
||
memory = axi.AxiMemoryModel(m, 'memory', clk, rst, memimg_name=memimg_name) | ||
memory.connect(ports, 'myaxi') | ||
|
||
uut = m.Instance(led, 'uut', | ||
params=m.connect_params(led), | ||
ports=m.connect_ports(led)) | ||
|
||
#simulation.setup_waveform(m, uut) | ||
simulation.setup_clock(m, clk, hperiod=5) | ||
init = simulation.setup_reset(m, rst, m.make_reset(), period=100) | ||
|
||
init.add( | ||
Delay(1000000), | ||
Systask('finish'), | ||
) | ||
|
||
return m | ||
|
||
|
||
def run(filename='tmp.v', simtype='iverilog', outputfile=None): | ||
|
||
if outputfile is None: | ||
outputfile = os.path.splitext(os.path.basename(__file__))[0] + '.out' | ||
|
||
memimg_name = 'memimg_' + outputfile | ||
|
||
test = mkTest(memimg_name=memimg_name) | ||
|
||
if filename is not None: | ||
test.to_verilog(filename) | ||
|
||
sim = simulation.Simulator(test, sim=simtype) | ||
rslt = sim.run(outputfile=outputfile) | ||
lines = rslt.splitlines() | ||
if simtype == 'verilator' and lines[-1].startswith('-'): | ||
rslt = '\n'.join(lines[:-1]) | ||
return rslt | ||
|
||
|
||
if __name__ == '__main__': | ||
rslt = run(filename='tmp.v') | ||
print(rslt) |
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
Oops, something went wrong.