-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from Ben1152000/feature/tests
Rewrite tests to use unittest module
- Loading branch information
Showing
20 changed files
with
287 additions
and
258 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 |
---|---|---|
@@ -1,28 +1,35 @@ | ||
|
||
## Instructions for how to update the version of the sootty package of PyPI: | ||
|
||
1) Update the version number in `setup.py`. | ||
2) Run this command to package the new version into the `dist` directory: | ||
1. Update the version number in `setup.py`. | ||
2. Run this command to package the new version into the `dist` directory: | ||
|
||
<!-- --> | ||
|
||
python3 setup.py sdist bdist_wheel | ||
|
||
|
||
3) Run to check that the package contains the correct files: | ||
3. Run to check that the package contains the correct files: | ||
|
||
<!-- --> | ||
|
||
tar tzf dist/sootty-<version>.tar.gz | ||
|
||
4) Run to check whether the package will correctly render to PyPI: | ||
4. Run to check whether the package will correctly render to PyPI: | ||
|
||
<!-- --> | ||
|
||
twine check dist/* | ||
|
||
5) Upload the newly created files to PyPI: | ||
5. Upload the newly created files to PyPI: | ||
|
||
<!-- well hey there sailor! don't delete these comments because they actually affect the markdown rendering :-) --> | ||
<!-- --> | ||
|
||
twine upload dist/sootty-<version>.tar.gz dist/sootty-<version>-py3-none-any.whl | ||
|
||
## Install project locally | ||
|
||
python3 -m pip install . | ||
|
||
## Run all unit tests | ||
|
||
python3 -m unittest test |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
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,2 @@ | ||
python3 -m pip install . | ||
python3 -m unittest discover |
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
File renamed without changes.
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,6 @@ | ||
from .test_all import TestStringMethods | ||
from .test_general import TestGeneral | ||
from .test_limits import TestLimits | ||
from .test_pyrtl import TestPyrtl | ||
from .test_style import TestStyle | ||
from .test_wires import TestWires |
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 @@ | ||
from sootty.storage import Wire | ||
|
||
import unittest | ||
|
||
class TestStringMethods(unittest.TestCase): | ||
|
||
def test_upper(self): | ||
self.assertEqual('foo'.upper(), 'FOO') | ||
|
||
if __name__ == '__main__': | ||
unittest.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,43 @@ | ||
import re, sys | ||
from subprocess import call, Popen, STDOUT, PIPE | ||
from sootty import WireTrace, Visualizer, VectorImage, Style | ||
|
||
import unittest | ||
|
||
|
||
class TestGeneral(unittest.TestCase): | ||
|
||
def test_svg_output(self): | ||
wiretrace = WireTrace.from_vcd("example/example1.vcd") | ||
|
||
assert type(wiretrace) == WireTrace | ||
|
||
image = Visualizer().to_svg(wiretrace, start=0, length=8) | ||
|
||
pattern = r"(?:<\?xml\b[^>]*>[^<]*)?(?:<!--.*?-->[^<]*)*(?:<svg|<!DOCTYPE svg)\b" | ||
prog = re.compile(pattern, re.DOTALL) | ||
assert prog.match(image.source) is not None | ||
|
||
image.display() | ||
|
||
|
||
def test_scope(self): | ||
wiretrace = WireTrace().from_vcd("example/example2.vcd") | ||
assert type(wiretrace) == WireTrace | ||
|
||
# def print_group(group, depth=0): | ||
# for wire in group.wires: | ||
# print('\t' * depth + wire.name) | ||
# for group in group.groups: | ||
# print('\t' * depth + group.name + ':') | ||
# print_group(group, depth + 1) | ||
|
||
# print_group(wiretrace.root) | ||
|
||
assert wiretrace.num_wires() == 26 | ||
image = Visualizer().to_svg(wiretrace, start=0, length=8) | ||
image.display() | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.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,30 @@ | ||
from sootty.parser import parser | ||
|
||
import unittest | ||
|
||
|
||
class TestLimits(unittest.TestCase): | ||
def test_parse_1(self): | ||
self.assertEqual( | ||
str(parser.parse("a + b & c - d + const 1").pretty("\t")), | ||
"&\n\t+\n\t\twire\ta\n\t\twire\tb\n\t+\n\t\t-\n\t\t\twire\tc\n\t\t\twire\td\n\t\tconst\t1\n", | ||
) | ||
|
||
def test_parse_2(self): | ||
self.assertEqual( | ||
str( | ||
parser.parse( | ||
"after (acc clk == const 5) & ready & value & (3 next data == const 64)" | ||
).pretty("\t") | ||
), | ||
"&\n\t&\n\t\t&\n\t\t\tafter\n\t\t\t\t==\n\t\t\t\t\tacc\n\t\t\t\t\t\twire\tclk\n\t\t\t\t\tconst\t5\n\t\t\twire\tready\n\t\twire\tvalue\n\t==\n\t\tnext\n\t\t\t3\n\t\t\twire\tdata\n\t\tconst\t64\n", | ||
) | ||
|
||
def test_parse_3(self): | ||
self.assertEqual( | ||
str(parser.parse("D1 & D2").pretty("\t")), "&\n\twire\tD1\n\twire\tD2\n" | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.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,112 @@ | ||
import pyrtl | ||
from sootty import WireTrace, Visualizer | ||
|
||
import unittest | ||
|
||
|
||
class TestPyrtl(unittest.TestCase): | ||
|
||
def test_counter(self): | ||
pyrtl.reset_working_block() | ||
|
||
i = pyrtl.Input(3, "i") | ||
counter = pyrtl.Register(3, "counter") | ||
o = pyrtl.Output(3, "o") | ||
|
||
update = counter + i | ||
counter.next <<= update | ||
o <<= counter | ||
|
||
sim = pyrtl.Simulation() | ||
sim.step_multiple({"i": [1, 1, 1, 1, 1]}) | ||
sim.tracer.render_trace() | ||
|
||
wiretrace = WireTrace.from_pyrtl(sim.tracer) | ||
Visualizer().to_svg(wiretrace).display() | ||
|
||
print(pyrtl.working_block()) | ||
|
||
|
||
def test_alu(self): | ||
pyrtl.reset_working_block() | ||
|
||
LW = 0 | ||
SW = 1 | ||
BEQ = 2 | ||
RT = 3 | ||
AND = 0 | ||
OR = 1 | ||
ADD = 2 | ||
SUB = 3 | ||
|
||
def ALU(ctrl, a, b): | ||
result = pyrtl.WireVector(16) | ||
zero = pyrtl.WireVector(1) | ||
|
||
with pyrtl.conditional_assignment: | ||
with ctrl == AND: | ||
result |= a & b | ||
with ctrl == OR: | ||
result |= a | b | ||
with ctrl == ADD: | ||
result |= a + b | ||
with ctrl == SUB: | ||
result |= a - b | ||
|
||
zero <<= result == 0 | ||
return result, zero | ||
|
||
def ALUControl(op, func): | ||
ctrl = pyrtl.WireVector(2, "ctrl") | ||
with pyrtl.conditional_assignment: | ||
with op == LW: | ||
ctrl |= 2 | ||
with op == SW: | ||
ctrl |= 2 | ||
with op == BEQ: | ||
ctrl |= 3 | ||
with op == RT: | ||
with func == 0: | ||
ctrl |= AND | ||
with func == 1: | ||
ctrl |= OR | ||
with func == 2: | ||
ctrl |= ADD | ||
with func == 3: | ||
ctrl |= SUB | ||
return ctrl | ||
|
||
op = pyrtl.Input(2, "op") | ||
a = pyrtl.Input(16, "a") | ||
b = pyrtl.Input(16, "b") | ||
func = pyrtl.Input(2, "func") | ||
|
||
r = pyrtl.Output(16, "result") | ||
z = pyrtl.Output(1, "zero") | ||
|
||
ctl = ALUControl(op, func) | ||
( | ||
r_o, | ||
z_o, | ||
) = ALU(ctl, a, b) | ||
r <<= r_o | ||
z <<= z_o | ||
|
||
sim_inputs = { | ||
"op": [0] * 2 + [1] * 2 + [2] * 2 + [3] * 2, | ||
"a": [2, 1] * 4, | ||
"b": [1, 0, 1, 0] * 2, | ||
"func": [0] * 6 + [0, 1], | ||
} | ||
|
||
sim = pyrtl.Simulation() | ||
|
||
sim.step_multiple(sim_inputs) | ||
sim.tracer.render_trace(trace_list=["op", "func", "a", "b", "result", "zero"]) | ||
|
||
wiretrace = WireTrace.from_pyrtl(sim.tracer) | ||
Visualizer().to_svg(wiretrace).display() | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Oops, something went wrong.