Skip to content
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

Tester Refactor #22

Merged
merged 25 commits into from
Aug 27, 2018
Merged

Tester Refactor #22

merged 25 commits into from
Aug 27, 2018

Conversation

rsetaluri
Copy link
Collaborator

@rsetaluri rsetaluri commented Aug 16, 2018

Started refactoring the tester and targets. Wanted to get some feedback on this -- still more to do if the direction is good. The commit msg should describe the new way of doing things.

@leonardt what do you think?

@@ -10,9 +10,9 @@ def test_tester_basic():
tester = fault.Tester(circ)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the serialization tests should be disjoint from the tester tests. the tester tests should just ensure that the series of actions generated is accurate (mostly trivial).

Copy link
Collaborator Author

@rsetaluri rsetaluri Aug 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

"d", m.In(m.Array(16, m.Array(20, m.Bit)))]


def test_all():
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test could be structured better, but just wanted to get in all the test functionality so we're sure nothing is broken.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pytest parametrization might be useful here (see https://docs.pytest.org/en/latest/parametrize.html)

f"{i}, \"{action.port.name}\");"]
if isinstance(action, actions.Eval):
return ["top->eval();"]
if isinstance(action, actions.Step):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

fault/tester.py Outdated
self.vectors[-1][index] = make_value(port, AnyValue)

def process(self, action):
if isinstance(action, (actions.Poke, actions.Expect)):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to deal with nested arrays here (i.e. tester.poke(circ.I[2]))

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


@staticmethod
def generate_action_code(i, action):
if isinstance(action, actions.Poke):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to deal with nested arrays --> flatten names

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the array flattening stuff is quite annoying, I'm not sure if there's a less complex solution to this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Owner

@leonardt leonardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me, carry on!

def __init__(self, steps, clock):
super().__init__()
self.steps = steps
self.clock = clock
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, I like this abstraction of Actions. I thought about this more, and I think this is the right approach in general. It's much more conservative in space (it records the changes to the input/output state of the circuit, rather than the entire input/output state contained in a full test vector). This state is realized in the simulation state itself, so there's no reason to duplicate the state in the test vector.

We can always generate the test vector version from this sequence of actions.

fault/tester.py Outdated
self.vectors[-1][index] = make_value(port, AnyValue)

def process(self, action):
if isinstance(action, (actions.Poke, actions.Expect)):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


@staticmethod
def generate_action_code(i, action):
if isinstance(action, actions.Poke):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the array flattening stuff is quite annoying, I'm not sure if there's a less complex solution to this.

"d", m.In(m.Array(16, m.Array(20, m.Bit)))]


def test_all():
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pytest parametrization might be useful here (see https://docs.pytest.org/en/latest/parametrize.html)

@rsetaluri
Copy link
Collaborator Author

@leonardt this should be ready for final review.

Refactoring tester to now just capture a sequence of "actions". Each
target can choose to interpret these actions however. These actions tend
to be more 1-to-1 with actions in the actual targets, making the
translation easier. The verilator target has been mostly fully
implemented.

TODO:
-- Verilator target nested arrays + name flattening
-- Python/CoreIR simulator target
tests/test_tester.py only tests how Tester produces actions (not
serialization). The serialization is tested specifically by testing
TestVectorBuilder (in tests/test_test_vector_builder.py).
Added the following:
-- Logic to optinally skip compilation to verilog in the target
-- Nested array support (flattening). This includes a utility function
   "verilator_name()" in verilator_utils.py.
Updated the magma simulator targets to work with the new action
interface. Note that the python simulator is not supported and not
tested for now. We issue a warning if it is used.
Renamed the corresponding class and files. This is to avoid pytest
warnings etc. Also makes the names cleaner.
Rather than compiling to verilator we now just check that the test
vectors have the structure we expect. This isolates the behavior the
test vector generation.
@coveralls
Copy link

coveralls commented Aug 19, 2018

Pull Request Test Coverage Report for Build 166

  • 239 of 270 (88.52%) changed or added relevant lines in 9 files are covered.
  • 10 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.8%) to 79.074%

Changes Missing Coverage Covered Lines Changed/Added Lines %
fault/verilator_utils.py 16 17 94.12%
fault/vector_builder.py 50 52 96.15%
fault/test_vectors.py 7 9 77.78%
fault/actions.py 23 25 92.0%
fault/verilator_target.py 56 59 94.92%
fault/value_utils.py 36 40 90.0%
fault/magma_simulator_target.py 24 29 82.76%
fault/tester.py 24 36 66.67%
Files with Coverage Reduction New Missed Lines %
fault/magma_simulator_target.py 1 82.35%
fault/array.py 4 59.09%
fault/test_vectors.py 5 87.8%
Totals Coverage Status
Change from base Build 149: -0.8%
Covered Lines: 427
Relevant Lines: 540

💛 - Coveralls

@leonardt
Copy link
Owner

@rsetaluri looks like the most recent checks passed. Is this ready for a final review?

@rsetaluri
Copy link
Collaborator Author

@leonardt yes it is ready for final review

Copy link
Owner

@leonardt leonardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, minor change request but I'll make it and do the merge. Thanks for the great work. The verilator target code looks much cleaner, and I think working with Actions is going to lead to better internal code (rather than dealing with test vector indices and such)

circ = common.TestNestedArraysCircuit
tester = fault.Tester(circ)
expected = [random.randint(0, (1 << 4) - 1) for i in range(3)]
expected = [_BV(random.randint(0, (1 << 4) - 1)) for i in range(3)]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could use random.rand_bv

@leonardt leonardt merged commit 26e09fa into master Aug 27, 2018
@leonardt leonardt deleted the refactor branch August 27, 2018 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants