• 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

43.75
/spinnman/messages/scp/impl/sdram_de_alloc.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 typing import Optional, overload
1✔
17
from spinn_utilities.overrides import overrides
1✔
18
from spinnman.messages.scp import SCPRequestHeader
1✔
19
from spinnman.messages.scp.abstract_messages import (
1✔
20
    AbstractSCPRequest, AbstractSCPResponse)
21
from spinnman.messages.scp.enums import AllocFree, SCPCommand, SCPResult
1✔
22
from spinnman.messages.sdp import SDPFlag, SDPHeader
1✔
23
from spinnman.exceptions import SpinnmanUnexpectedResponseCodeException
1✔
24

25
_ONE_WORD = struct.Struct("<I")
1✔
26

27

28
class _SCPSDRAMDeAllocResponse(AbstractSCPResponse):
1✔
29
    """
30
    An SCP response to a request to deallocate SDRAM.
31
    """
32
    __slots__ = (
1✔
33
        "_number_of_blocks_freed",
34
        "_read_n_blocks_freed")
35

36
    def __init__(self, read_n_blocks_freed: bool = False):
1✔
37
        """
38
        """
39
        super().__init__()
×
40
        self._number_of_blocks_freed = 0
×
41
        self._read_n_blocks_freed = read_n_blocks_freed
×
42

43
    @overrides(AbstractSCPResponse.read_data_bytestring)
1✔
44
    def read_data_bytestring(self, data: bytes, offset: int):
1✔
45
        result = self.scp_response_header.result
×
46
        if result != SCPResult.RC_OK:
×
47
            raise SpinnmanUnexpectedResponseCodeException(
×
48
                "SDRAM deallocation", "CMD_DEALLOC", result.name)
49
        if self._read_n_blocks_freed:
×
50
            self._number_of_blocks_freed = _ONE_WORD.unpack_from(
×
51
                data, offset)[0]
52

53
            # check that the base address is not null (0 in python case) as
54
            # this reflects a issue in command on SpiNNaker side
55
            if self._number_of_blocks_freed == 0:
×
56
                raise SpinnmanUnexpectedResponseCodeException(
×
57
                    "SDRAM deallocation response base address", "CMD_DEALLOC",
58
                    result.name)
59

60
    @property
1✔
61
    def number_of_blocks_freed(self) -> int:
1✔
62
        """
63
        The number of allocated blocks that have been freed from the
64
        app_id given.
65

66
        :rtype: int
67
        """
68
        return self._number_of_blocks_freed
×
69

70

71
class SDRAMDeAlloc(AbstractSCPRequest[_SCPSDRAMDeAllocResponse]):
1✔
72
    """
73
    An SCP Request to free space in the SDRAM.
74
    """
75
    __slots__ = "_read_n_blocks_freed",
1✔
76

77
    @overload
78
    def __init__(self, x: int, y: int, *, app_id: int,
79
                 base_address: None = None):
80
        ...
81

82
    @overload
83
    def __init__(self, x: int, y: int, *, app_id: None = None,
84
                 base_address: int):
85
        ...
86

87
    def __init__(self, x: int, y: int, *, app_id: Optional[int] = None,
1✔
88
                 base_address: Optional[int] = None):
89
        """
90
        :param int x:
91
            The x-coordinate of the chip to allocate on, between 0 and 255
92
        :param int y:
93
            The y-coordinate of the chip to allocate on, between 0 and 255
94
        :param int app_id: The ID of the application, between 0 and 255
95
        :param base_address: The start address in SDRAM to which the block
96
            needs to be deallocated, or `None` if deallocating via app_id
97
        :type base_address: int or None
98
        """
99
        # pylint: disable=unsupported-binary-operation
100
        if base_address is not None:
×
101
            assert app_id is None
×
102
            super().__init__(
×
103
                SDPHeader(
104
                    flags=SDPFlag.REPLY_EXPECTED, destination_port=0,
105
                    destination_cpu=0, destination_chip_x=x,
106
                    destination_chip_y=y),
107
                SCPRequestHeader(command=SCPCommand.CMD_ALLOC),
108
                argument_1=(
109
                    AllocFree.
110
                    FREE_SDRAM_BY_POINTER.value),  # @UndefinedVariable
111
                argument_2=base_address)
112
            self._read_n_blocks_freed = False
×
113
        else:
114
            assert app_id is not None
×
115
            super().__init__(
×
116
                SDPHeader(
117
                    flags=SDPFlag.REPLY_EXPECTED, destination_port=0,
118
                    destination_cpu=0, destination_chip_x=x,
119
                    destination_chip_y=y),
120
                SCPRequestHeader(command=SCPCommand.CMD_ALLOC),
121
                argument_1=(
122
                    app_id << 8 |
123
                    AllocFree.
124
                    FREE_SDRAM_BY_APP_ID.value))  # @UndefinedVariable
125
            self._read_n_blocks_freed = True
×
126

127
    @overrides(AbstractSCPRequest.get_scp_response)
1✔
128
    def get_scp_response(self) -> _SCPSDRAMDeAllocResponse:
1✔
129
        return _SCPSDRAMDeAllocResponse(self._read_n_blocks_freed)
×
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