• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SpiNNakerManchester / SpiNNMan / 6574804013

19 Oct 2023 12:47PM UTC coverage: 51.937% (+1.2%) from 50.777%
6574804013

Pull #327

github

Christian-B
typing changes
Pull Request #327: Type Annotations and Checking

105 of 1288 branches covered (0.0%)

Branch coverage included in aggregate %.

2375 of 2375 new or added lines in 180 files covered. (100.0%)

4775 of 8108 relevant lines covered (58.89%)

0.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

38.3
/spinnman/processes/get_routes_process.py
1
# Copyright (c) 2015 The University of Manchester
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
#     https://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14

15
import struct
1✔
16
from functools import partial
1✔
17
from typing import List, Optional
1✔
18
from spinnman.messages.scp.impl.read_memory import ReadMemory, Response
1✔
19
from spinn_machine import MulticastRoutingEntry, Router
1✔
20
from .abstract_multi_connection_process import AbstractMultiConnectionProcess
1✔
21
from .abstract_multi_connection_process_connection_selector import (
1✔
22
    ConnectionSelector)
23
from spinnman.constants import UDP_MESSAGE_MAX_SIZE
1✔
24

25
# There are 1024 entries in a routing table
26
_N_ENTRIES = 1024
1✔
27

28
# 16 entries fit in a 256-byte read
29
_ENTRIES_PER_READ = 16
1✔
30

31
# 64 reads of 16 entries are required for 1024 entries
32
_N_READS = 64
1✔
33

34
_ROUTE_ENTRY_PATTERN = struct.Struct("<2xBxIII")
1✔
35

36

37
class GetMultiCastRoutesProcess(AbstractMultiConnectionProcess[Response]):
1✔
38
    """
39
    A process for reading the multicast routing table of a SpiNNaker chip.
40
    """
41
    __slots__ = (
1✔
42
        "_app_id",
43
        "_entries")
44

45
    def __init__(self, connection_selector: ConnectionSelector,
1✔
46
                 app_id: Optional[int] = None):
47
        """
48
        :param ConnectionSelector connection_selector:
49
        :param int app_id:
50
        """
51
        super().__init__(connection_selector)
×
52
        self._entries: List[Optional[MulticastRoutingEntry]] = \
×
53
            [None] * _N_ENTRIES
54
        self._app_id = app_id
×
55

56
    def _add_routing_entry(
1✔
57
            self, route_no: int, offset: int, app_id: int, route: int,
58
            key: int, mask: int):
59
        # pylint: disable=too-many-arguments
60
        if route >= 0xFF000000:
×
61
            return
×
62
        if self._app_id is not None and self._app_id != app_id:
×
63
            return
×
64

65
        # Convert bit-set into list of (set) IDs
66
        processor_ids, link_ids = \
×
67
            Router.convert_spinnaker_route_to_routing_ids(route)
68

69
        self._entries[route_no + offset] = MulticastRoutingEntry(
×
70
            key, mask, processor_ids=processor_ids, link_ids=link_ids,
71
            defaultable=False)
72

73
    def __handle_response(self, offset: int, response: Response):
1✔
74
        for route_no in range(_ENTRIES_PER_READ):
×
75
            entry = _ROUTE_ENTRY_PATTERN.unpack_from(
×
76
                response.data,
77
                response.offset + route_no * _ROUTE_ENTRY_PATTERN.size)
78
            self._add_routing_entry(route_no, offset, *entry)
×
79

80
    def get_routes(self, x: int, y: int,
1✔
81
                   base_address: int) -> List[MulticastRoutingEntry]:
82
        """
83
        :param int x:
84
        :param int y:
85
        :param int base_address:
86
        :rtype: list(~spinn_machine.MulticastRoutingEntry)
87
        """
88
        # Create the read requests
89
        offset = 0
×
90
        scamp_coords = x, y, 0
×
91
        with self._collect_responses():
×
92
            for _ in range(_N_READS):
×
93
                self._send_request(
×
94
                    ReadMemory(
95
                        scamp_coords, base_address + (offset * 16),
96
                        UDP_MESSAGE_MAX_SIZE),
97
                    partial(self.__handle_response, offset))
98
                offset += _ENTRIES_PER_READ
×
99

100
        return [entry for entry in self._entries if entry is not None]
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc