• 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

46.55
/spinnman/spalloc/spalloc_eieio_connection.py
1
# Copyright (c) 2022 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
"""
1✔
15
API of the client for the Spalloc web service.
16
"""
17

18
import struct
1✔
19
from typing import Optional
1✔
20
from spinn_utilities.abstract_base import AbstractBase, abstractmethod
1✔
21
from spinn_utilities.overrides import overrides
1✔
22
from spinn_utilities.typing.coords import XY
1✔
23
from spinnman.connections.udp_packet_connections import EIEIOConnection
1✔
24
from spinnman.exceptions import SpinnmanTimeoutException
1✔
25
from spinnman.messages.eieio import (
1✔
26
    AbstractEIEIOMessage,
27
    read_eieio_command_message, read_eieio_data_message)
28
from spinnman.messages.sdp import SDPMessage, SDPFlag, SDPHeader
1✔
29
from spinnman.messages.scp.impl import IPTagSet
1✔
30
from .spalloc_proxied_connection import SpallocProxiedConnection
1✔
31

32
_ONE_SHORT = struct.Struct("<H")
1✔
33
_TWO_SKIP: bytes = b'\0\0'
1✔
34
_NUM_UPDATE_TAG_TRIES = 3
1✔
35
_UPDATE_TAG_TIMEOUT = 1.0
1✔
36

37

38
class SpallocEIEIOConnection(
1✔
39
        EIEIOConnection, SpallocProxiedConnection, metaclass=AbstractBase):
40
    """
41
    The socket interface supported by proxied EIEIO connected sockets.
42
    This emulates an :py:class:`EIEOConnection` opened with a remote address
43
    specified.
44
    """
45
    __slots__ = ()
1✔
46

47
    @overrides(EIEIOConnection.send_eieio_message)
1✔
48
    def send_eieio_message(self, eieio_message):
1✔
49
        # Not normally used, as packets need headers to go to SpiNNaker
50
        self.send(eieio_message.bytestring)
×
51

52
    def send_eieio_message_to_core(
1✔
53
            self, eieio_message: AbstractEIEIOMessage, x: int, y: int, p: int):
54
        sdp_message = SDPMessage(
×
55
            SDPHeader(
56
                flags=SDPFlag.REPLY_NOT_EXPECTED, tag=0,
57
                destination_port=1, destination_cpu=p,
58
                destination_chip_x=x, destination_chip_y=y,
59
                source_port=0, source_cpu=0,
60
                source_chip_x=0, source_chip_y=0),
61
            data=eieio_message.bytestring)
62
        self.send(_TWO_SKIP + sdp_message.bytestring)
×
63

64
    @overrides(EIEIOConnection.receive_eieio_message)
1✔
65
    def receive_eieio_message(
1✔
66
            self, timeout: Optional[float] = None) -> AbstractEIEIOMessage:
67
        data = self.receive(timeout)
×
68
        header = _ONE_SHORT.unpack_from(data)[0]
×
69
        if header & 0xC000 == 0x4000:
×
70
            return read_eieio_command_message(data, 0)
×
71
        return read_eieio_data_message(data, 0)
×
72

73
    @property
1✔
74
    @abstractmethod
1✔
75
    def _coords(self) -> XY:
1✔
76
        """
77
        The X, Y coordinates of the chip this connection is connected to.
78

79
        :rtype: tuple(int,int)
80
        """
81
        raise NotImplementedError
82

83
    def update_tag(self, tag: int, do_receive: bool = True):
1✔
84
        """
85
        Update the given tag on the connected Ethernet-enabled chip to send
86
        messages to this connection.
87

88
        :param int tag: The tag ID to update
89
        :param bool do_receive:
90
            Whether to do the reception of the response or not
91
        :raises SpinnmanTimeoutException:
92
            If the message isn't handled within a reasonable timeout.
93
        :raises SpinnmanUnexpectedResponseCodeException:
94
            If the message is rejected by SpiNNaker/SCAMP.
95
        """
96
        x, y = self._coords
×
97
        request = IPTagSet(
×
98
            x, y, [0, 0, 0, 0], 0, tag, strip=True, use_sender=True)
99
        request.sdp_header.flags = SDPFlag.REPLY_EXPECTED_NO_P2P
×
100
        request.sdp_header.update_for_send(x, y)
×
101
        data = _TWO_SKIP + request.bytestring
×
102
        for _try in range(_NUM_UPDATE_TAG_TRIES):
×
103
            try:
×
104
                self.send(data)
×
105
                if do_receive:
×
106
                    response_data = self.receive(_UPDATE_TAG_TIMEOUT)
×
107
                    request.get_scp_response().read_bytestring(
×
108
                        response_data, len(_TWO_SKIP))
109
                return
×
110
            except SpinnmanTimeoutException as e:
×
111
                if _try + 1 == _NUM_UPDATE_TAG_TRIES:
×
112
                    raise e
×
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