Skip to content

Commit

Permalink
Add get_router_diagnostics
Browse files Browse the repository at this point in the history
This returns the router counter diagnostics as a namedtuple.
  • Loading branch information
mundya committed Jun 4, 2015
1 parent 15e1ab8 commit 5ef8e9e
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
28 changes: 28 additions & 0 deletions rig/machine_control/machine_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,21 @@ def get_processor_status(self, p, x, y):
state.pop("__PAD")
return ProcessorStatus(**state)

@ContextMixin.use_contextual_arguments()
def get_router_diagnostics(self, x, y):
"""Get the values of the router diagnostic counters.
Returns
-------
:py:class:`~.RouterDiagnostics`
Description of the state of the counters.
"""
# Read the block of memory
data = self.read(0xe1000300, 64, x=x, y=y)

# Convert to 16 ints, then process that as the appropriate tuple type
return RouterDiagnostics(*struct.unpack("<16I", data))

@ContextMixin.use_contextual_arguments()
def iptag_set(self, iptag, addr, port, x, y):
"""Set the value of an IPTag.
Expand Down Expand Up @@ -1451,6 +1466,19 @@ class ProcessorStatus(collections.namedtuple(
"""


class RouterDiagnostics(collections.namedtuple(
"RouterDiagnostics", ["local_multicast", "external_multicast",
"local_p2p", "external_p2p",
"local_nearest_neighbour",
"external_nearest_neighbour",
"local_fixed_route", "external_fixed_route",
"dropped_multicast", "dropped_p2p",
"dropped_nearest_neighbour", "dropped_fixed_route",
"counter12", "counter13", "counter14", "counter15"])
):
"""Read out of the diagnostic counters of a SpiNNaker router."""


class IPTag(collections.namedtuple("IPTag",
"addr mac port timeout flags count rx_port "
"spin_addr spin_port")):
Expand Down
36 changes: 36 additions & 0 deletions tests/machine_control/test_machine_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,42 @@ def mock_read_struct_field(struct_name, field, x, y, p=0):
assert ps.app_name == "Hello World!"
assert ps.rt_code is consts.RuntimeException.api_startup_failure

@pytest.mark.parametrize("_x, _y", [(0, 5), (7, 10)])
def test_get_router_diagnostics(self, _x, _y):
# Check that a read is made from the right region of memory and that
# the resulting data is unpacked correctly
cn = MachineController("localhost")
def mock_read(address, length, x, y, p=0):
assert x == _x
assert y == _y
assert p == 0
assert address == 0xe1000300
assert length == 64
return struct.pack("<16I", *list(range(16)))
cn.read = mock.Mock(side_effect=mock_read)

# Get the router status
with cn(x=_x, y=_y):
rd = cn.get_router_diagnostics()

# Assert this matches what we'd expect
assert rd.local_multicast == 0
assert rd.external_multicast == 1
assert rd.local_p2p == 2
assert rd.external_p2p == 3
assert rd.local_nearest_neighbour == 4
assert rd.external_nearest_neighbour == 5
assert rd.local_fixed_route == 6
assert rd.external_fixed_route == 7
assert rd.dropped_multicast == 8
assert rd.dropped_p2p == 9
assert rd.dropped_nearest_neighbour == 10
assert rd.dropped_fixed_route == 11
assert rd.counter12 == 12
assert rd.counter13 == 13
assert rd.counter14 == 14
assert rd.counter15 == 15

@pytest.mark.parametrize("n_args", [0, 3])
def test_flood_fill_aplx_args_fails(self, n_args):
"""Test that calling flood_fill_aplx with an invalid number of
Expand Down

0 comments on commit 5ef8e9e

Please sign in to comment.