Skip to content

Commit

Permalink
calloc_sdram for clearing and allocating SDRAM
Browse files Browse the repository at this point in the history
  • Loading branch information
mundya committed Oct 26, 2015
1 parent 9208c5f commit ee33345
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
16 changes: 16 additions & 0 deletions nengo_spinnaker/utils/machine_control.py
Expand Up @@ -43,3 +43,19 @@ def test_and_boot(controller, hostname, machine_width, machine_height):
logger.info(
"Board is booted with {} v{:.2f}".format(sver.version_string,
sver.version))


def calloc_sdram(controller, size, **kwargs):
"""Allocate and clear a region of SDRAM.
Returns
-------
int
Address of the cleared and allocated space in SDRAM.
"""
# Allocate the region in SDRAM, store the start address and clear the
# memory.
mem = controller.sdram_alloc_as_filelike(size, **kwargs)
addr = mem.address
mem.write(b'\x00' * size)
return addr
18 changes: 18 additions & 0 deletions tests/utils/test_machine_control.py
Expand Up @@ -7,6 +7,24 @@
from nengo_spinnaker.utils import machine_control


@pytest.mark.parametrize("n_bytes", [100, 123])
def test_calloc_sdram(n_bytes):
"""Test allocating and zeroing a region of SDRAM."""
# Create a mock machine controller
cn = mock.Mock()
mem = cn.sdram_alloc_as_filelike.return_value = mock.Mock()
mem.address = 0x67800000

# Check that calling calloc_sdram() calls the controller correctly
addr = machine_control.calloc_sdram(cn, n_bytes)

# Assert that the returned address is correct
assert addr == mem.address

# Check that sufficient zeroes were written
mem.write.assert_called_once_with(b'\x00' * n_bytes)


class TestTestAndBoot(object):
def test_board_is_checked(self):
"""Test that we're happy if the board responds to an sver."""
Expand Down

0 comments on commit ee33345

Please sign in to comment.