• 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

47.06
/spinnman/processes/read_memory_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 functools
1✔
16
from typing import Callable
1✔
17
from spinn_utilities.typing.coords import XYP
1✔
18
from spinnman.messages.scp.impl import ReadLink, ReadMemory
1✔
19
from spinnman.messages.scp.impl.read_memory import Response
1✔
20
from .abstract_multi_connection_process import AbstractMultiConnectionProcess
1✔
21
from spinnman.constants import UDP_MESSAGE_MAX_SIZE
1✔
22
from spinnman.messages.scp.abstract_messages import AbstractSCPRequest
1✔
23
from .abstract_multi_connection_process_connection_selector import (
1✔
24
    ConnectionSelector)
25

26

27
class ReadMemoryProcess(AbstractMultiConnectionProcess[Response]):
1✔
28
    """
29
    A process for reading memory on a SpiNNaker chip.
30
    """
31
    __slots__ = ("_view", )
1✔
32

33
    def __init__(self, connection_selector: ConnectionSelector):
1✔
34
        """
35
        :param ConnectionSelector connection_selector:
36
        """
37
        super().__init__(connection_selector)
×
38
        self._view = memoryview(b'')
×
39

40
    def __handle_response(self, offset: int, response: Response):
1✔
41
        self._view[offset:offset + response.length] = response.data[
×
42
            response.offset:response.offset + response.length]
43

44
    def read_memory(
1✔
45
            self, coordinates: XYP, base_address: int, length: int) -> bytes:
46
        """
47
        Read some memory from a core.
48

49
        :param tuple(int,int,int) coordinates:
50
        :param int base_address:
51
        :param int length:
52
        :rtype: bytearray
53
        """
54
        return self._read_memory(
×
55
            base_address, length,
56
            functools.partial(ReadMemory, coordinates))
57

58
    def read_link_memory(self, coordinates: XYP, link: int,
1✔
59
                         base_address: int, length: int) -> bytes:
60
        """
61
        Read some memory from the neighbour of a core.
62

63
        :param tuple(int,int,int) coordinates:
64
        :param int link:
65
        :param int base_address:
66
        :param int length:
67
        :rtype: bytearray
68
        """
69
        return self._read_memory(
×
70
            base_address, length,
71
            functools.partial(ReadLink, coordinates, link))
72

73
    def _read_memory(
1✔
74
            self, base_address: int, length: int,
75
            packet_class: Callable[
76
                [int, int], AbstractSCPRequest[Response]]) -> bytes:
77
        data = bytearray(length)
×
78
        self._view = memoryview(data)
×
79
        n_bytes = length
×
80
        offset = 0
×
81

82
        with self._collect_responses():
×
83
            while n_bytes > 0:
×
84
                bytes_to_get = min((n_bytes, UDP_MESSAGE_MAX_SIZE))
×
85
                self._send_request(
×
86
                    packet_class(base_address + offset, bytes_to_get),
87
                    functools.partial(self.__handle_response, offset))
88
                n_bytes -= bytes_to_get
×
89
                offset += bytes_to_get
×
90

91
        return bytes(data)
×
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