Move tests from lib/memory.py to separate unit test (#2258)

pull/2265/head
Jason An 1 year ago committed by GitHub
parent 0ab077ffde
commit 211b82a7a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -48,11 +48,6 @@ def page_offset(address: int) -> int:
return address & (PAGE_SIZE - 1)
# TODO: Move to a test
assert round_down(0xDEADBEEF, 0x1000) == 0xDEADB000
assert round_up(0xDEADBEEF, 0x1000) == 0xDEADC000
class Page:
"""
Represents the address space and page permissions of at least

@ -0,0 +1,33 @@
from __future__ import annotations
import sys
from unittest.mock import MagicMock
# Replace `pwndbg.commands` module with a mock to prevent import errors, as well
# as the `load_commands` function
module_name = "pwndbg.commands"
module = MagicMock(__name__=module_name, load_commands=lambda: None)
sys.modules[module_name] = module
# Load the mocks for the `gdb` and `gdblib` modules
import mocks.gdb
import mocks.gdblib # noqa: F401
# We must import the function under test after all the mocks are imported
from pwndbg.lib.memory import round_down
from pwndbg.lib.memory import round_up
def test_basic_rounding():
assert round_down(0xDEADBEEF, 0x1000) == 0xDEADB000
assert round_up(0xDEADBEEF, 0x1000) == 0xDEADC000
def test_many_rounding():
for n in range(0x100):
for i in range(8):
alignment = 1 << i
down = round_down(n, alignment)
up = round_up(n, alignment)
assert down <= n and down + alignment > n and down % alignment == 0
assert up >= n and up - alignment < n and up % alignment == 0
Loading…
Cancel
Save