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

Add __str__ methods for actions #26

Merged
merged 6 commits into from
Sep 11, 2018
Merged

Add __str__ methods for actions #26

merged 6 commits into from
Sep 11, 2018

Conversation

leonardt
Copy link
Owner

Convenience methods for debugging.

For example, with this change

diff --git a/fault/magma_simulator_target.py b/fault/magma_simulator_target.py
index 8bfc66b..2b09d84 100644
--- a/fault/magma_simulator_target.py
+++ b/fault/magma_simulator_target.py
@@ -24,6 +24,7 @@ class MagmaSimulatorTarget(Target):
     def run(self):
         simulator = self.backend_cls(self.circuit, self.clock)
         for action in self.actions:
+            print(action)
             if isinstance(action, actions.Poke):
                 value = action.value
                 # Python simulator does not support setting Bit with

You get a nice printout, such as

Poke(PISO10.PI, 956)
Poke(PISO10.SI, 0)
Poke(PISO10.LOAD, 1)
Step(2, PISO10.CLK)
Poke(PISO10.PI, 255)
Poke(PISO10.SI, 0)
Poke(PISO10.LOAD, 0)
Step(2, PISO10.CLK)
Expect(PISO10.O, 1)

fault/actions.py Outdated

class Step(Action):
def __init__(self, steps, clock):
super().__init__()
self.steps = steps
self.clock = clock

def __str__(self):
return f"Step({self.steps}, {self.clock.debug_name})"
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe Step({self.clock.debug_name}, steps={self.steps}) to make it more clear? Idk how standard the 'steps' argument is.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Sure, I was having it match the __init__ call, so if we go with this, I'd want to update the __init__ to match

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fair enough. If it's not too much refactoring that seems more uniform. Otherwise, it is fine as is.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Done

@coveralls
Copy link

coveralls commented Sep 11, 2018

Pull Request Test Coverage Report for Build 188

  • 11 of 11 (100.0%) changed or added relevant lines in 2 files are covered.
  • 3 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.5%) to 79.529%

Files with Coverage Reduction New Missed Lines %
fault/magma_simulator_target.py 3 84.21%
Totals Coverage Status
Change from base Build 167: 0.5%
Covered Lines: 439
Relevant Lines: 552

💛 - Coveralls

fault/tester.py Outdated
@@ -1,4 +1,4 @@
import magma
iclockmport magma
Copy link
Collaborator

Choose a reason for hiding this comment

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

oops :D

Copy link
Owner Author

Choose a reason for hiding this comment

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

heh, that's what I get for no tests. Fixed, and pushed a test for the string methods.

@leonardt
Copy link
Owner Author

Oh, forgot to update the Step references in the tests directory

@leonardt leonardt merged commit 104502c into master Sep 11, 2018
@leonardt leonardt deleted the action-str branch September 11, 2018 22:49
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