Skip to content
This repository was archived by the owner on Jun 24, 2026. It is now read-only.

Fix type confusion in manual CPU tests; delete dead testing code#1669

Merged
ehennenfent merged 1 commit into
masterfrom
simplify-test-code
Apr 16, 2020
Merged

Fix type confusion in manual CPU tests; delete dead testing code#1669
ehennenfent merged 1 commit into
masterfrom
simplify-test-code

Conversation

@bradlarsen

Copy link
Copy Markdown

It turns out that most of tests/native/mockmem.py was dead code to begin with. Additionally, using typeguard during testing (see #1584), it is revealed that the use of tests.native.mockmem.Memory turns some type hints elsewhere into lies (since the mocked version isn't a subclass of Memory).

The simplest fix: massage the single file that uses tests.native.mockmem.Memory, and then delete that whole file.

Comment on lines -19 to -37
class ROOperand:
""" Mocking class for operand ronly """

def __init__(self, size, value):
self.size = size
self.value = value

def read(self):
return self.value & ((1 << self.size) - 1)


class RWOperand(ROOperand):
""" Mocking class for operand rw """

def write(self, value):
self.value = value & ((1 << self.size) - 1)
return self.value


Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Note, this was already dead code, prior to these changes.

Comment on lines -173 to -188
class ROOperand:
""" Mocking class for operand ronly """

def __init__(self, size, value):
self.size = size
self.value = value

def read(self):
return self.value & ((1 << self.size) - 1)

class RWOperand(ROOperand):
""" Mocking class for operand rw """

def write(self, value):
self.value = value & ((1 << self.size) - 1)
return self.value

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Note, this was already dead code, prior to these changes.

Comment on lines -189 to -197

def setUp(self):
mem = MockMemory()
self.cpu = I386Cpu(mem) # TODO reset cpu in between tests...
# TODO mock getchar/putchar in case the instruction accesses memory directly

def tearDown(self):
self.cpu = None

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Note: the self.cpu parameter was only used in a few tests in this file previously. So instead of creating & destroying it around each test, I changed the code to explicitly create a Cpu object only within the test cases that use it.

@ehennenfent ehennenfent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Not much to comment here since it looks like most of the diff is s/self.cpu/cpu/. I'm assuming this will make #1660 easier.

@ehennenfent
ehennenfent merged commit a6ae85a into master Apr 16, 2020
@ehennenfent
ehennenfent deleted the simplify-test-code branch April 16, 2020 21:04
ekilmer added a commit that referenced this pull request Apr 23, 2020
* master: (28 commits)
  Rework syscall invocation for proper behavior under typeguard (#1672)
  printable_bytes (#1671)
  Fix several incorrect type hints (#1668)
  Add type hints to several parts of Manticore (#1667)
  Fix type confusion in manual CPU tests; delete dead testing code (#1669)
  Rework WASM Imports and Fix Typos (#1666)
  Work on "Model is not Available" errors in tests (#1659)
  Fix TypeGuard Errors in WASM Module (#1601)
  Remove unused arg ans separate output from workspace (#1651)
  Add a badge to README.md for LGTM (#1647)
  Fix 2 problems in Linux `sys_open` support & add type hints (#1657)
  Fix LGTM Errors (#1656)
  Delay WASM Branch Condition Concretization (#1641)
  Add feature for SymbolicSocket through sys_accept (#1618)
  Add a bunch of type hints & fix a few issues with Linux platform emulation (#1645)
  Bump to CheckoutV2 (#1654)
  Add support for `sys_arm_fadvise64_64` (#1648)
  Add __slots__ to expressions (#1635)
  Swap remaining uses of `Z3Solver()` to use the singleton interface (#1649)
  CI: have pytest report 100 slowest tests (#1646)
  ...
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants