Skip to content

Commit

Permalink
Merge pull request #353 from SpiNNakerManchester/version_fix
Browse files Browse the repository at this point in the history
Version fix
  • Loading branch information
rowleya authored Aug 3, 2023
2 parents f4f1847 + d4feab0 commit 5713976
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 77 deletions.
2 changes: 1 addition & 1 deletion quick_tests/quick_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
logging.basicConfig(level=logging.INFO)
logging.getLogger("spinnman.transceiver").setLevel(logging.DEBUG)

unittest_setup()
board_config = BoardTestConfiguration()
board_config.set_up_remote_board()

Expand Down Expand Up @@ -352,7 +353,6 @@ def print_transceiver_tests(transceiver):
print(heap_element)


unittest_setup()
with create_transceiver_from_hostname(
board_config.remotehost, board_config.board_version,
bmp_connection_data=board_config.bmp_names,
Expand Down
9 changes: 0 additions & 9 deletions spinnman/board_test_configuration.cfg

This file was deleted.

50 changes: 21 additions & 29 deletions spinnman/board_test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import configparser
from contextlib import closing
import os
import socket
import unittest
from spinn_utilities.config_holder import set_config
from spinn_utilities.ping import Ping
from spinnman.model import BMPConnectionData
# from spinnman.model import BMPConnectionData

_LOCALHOST = "127.0.0.1"
# Microsoft invalid IP address. For more details see:
Expand All @@ -30,43 +27,38 @@
class BoardTestConfiguration(object):

def __init__(self):
self.localhost = None
self.localport = None
self.remotehost = None
self.board_version = None
self.bmp_names = None
self.auto_detect_bmp = None

self._config = configparser.RawConfigParser()
config_file = os.path.join(
os.path.dirname(__file__), "board_test_configuration.cfg")
self._config.read(config_file)

def set_up_local_virtual_board(self):
self.localhost = _LOCALHOST
self.localport = _PORT
self.remotehost = _LOCALHOST
self.board_version = self._config.getint("Machine", "version")
self.board_version = 5

def set_up_remote_board(self):
self.remotehost = self._config.get("Machine", "machineName")
if not Ping.host_is_reachable(self.remotehost):
raise unittest.SkipTest("test board appears to be down")
self.board_version = self._config.getint("Machine", "version")
self.bmp_names = self._config.get("Machine", "bmp_names")
if self.bmp_names == "None":
self.bmp_names = None
if Ping.host_is_reachable("192.168.240.253"):
self.remotehost = "192.168.240.253"
self.board_version = 3
set_config("Machine", "version", 3)
self.auto_detect_bmp = False
elif Ping.host_is_reachable("spinn-4.cs.man.ac.uk"):
self.remotehost = "spinn-4.cs.man.ac.uk"
self.board_version = 5
set_config("Machine", "version", 5)
elif Ping.host_is_reachable("192.168.240.1"):
self.remotehost = "192.168.240.1"
self.board_version = 5
set_config("Machine", "version", 5)
else:
self.bmp_names = [BMPConnectionData(self.bmp_names, [0], None)]
self.auto_detect_bmp = \
self._config.getboolean("Machine", "auto_detect_bmp")
self.localport = _PORT
with closing(socket.socket(socket.AF_INET, socket.SOCK_DGRAM)) as s:
s.connect((self.remotehost, _PORT))
self.localhost = s.getsockname()[0]
raise unittest.SkipTest("None of the test boards reachable")

# it always was None but this is what to do if not
# self.bmp_names = BMPConnectionData(0, 0, self.bmp_names, [0], None)

def set_up_nonexistent_board(self):
self.localhost = None
self.localport = _PORT
self.remotehost = _NOHOST
self.board_version = self._config.getint("Machine", "version")
self.board_version = None
3 changes: 2 additions & 1 deletion spinnman/get_cores_in_run_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from spinnman.transceiver import create_transceiver_from_hostname
from spinn_machine import CoreSubsets, CoreSubset
from spinnman.board_test_configuration import BoardTestConfiguration
from spinnman.config_setup import unittest_setup
from spinnman.model.enums import CPUState

SCAMP_ID = 0
IGNORED_IDS = {SCAMP_ID, 16} # WHY 16?

Expand Down Expand Up @@ -104,6 +104,7 @@ def main(args):
"""
Runs the script.
"""
unittest_setup()
ap = argparse.ArgumentParser(
description="Check the state of a SpiNNaker machine.")
ap.add_argument(
Expand Down
19 changes: 9 additions & 10 deletions unittests/connection_tests/test_udp_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@
from spinnman.messages.scp.impl.get_version_response import GetVersionResponse
from spinnman.board_test_configuration import BoardTestConfiguration

board_config = BoardTestConfiguration()


class TestUDPConnection(unittest.TestCase):

def setUp(self):
unittest_setup()
self.board_config = BoardTestConfiguration()

def test_scp_version_request_and_response_board(self):
board_config.set_up_remote_board()
self.board_config.set_up_remote_board()
connection = SCAMPConnection(
remote_host=board_config.remotehost)
remote_host=self.board_config.remotehost)
scp_req = GetVersion(0, 0, 0)
scp_response = GetVersionResponse()
connection.send_scp_request(scp_req)
Expand All @@ -43,28 +42,28 @@ def test_scp_version_request_and_response_board(self):
scp_response._scp_response_header._result, SCPResult.RC_OK)

def test_scp_read_link_request_and_response_board(self):
board_config.set_up_remote_board()
self.board_config.set_up_remote_board()
connection = SCAMPConnection(
remote_host=board_config.remotehost)
remote_host=self.board_config.remotehost)
scp_link = ReadLink(0, 0, 0, 0x70000000, 250)
connection.send_scp_request(scp_link)
result, _, _, _ = connection.receive_scp_response()
self.assertEqual(result, SCPResult.RC_OK)

def test_scp_read_memory_request_and_response_board(self):
board_config.set_up_remote_board()
self.board_config.set_up_remote_board()
connection = SCAMPConnection(
remote_host=board_config.remotehost)
remote_host=self.board_config.remotehost)
scp_link = ReadMemory(0, 0, 0x70000000, 256)
connection.send_scp_request(scp_link)
result, _, _, _ = connection.receive_scp_response()
self.assertEqual(result, SCPResult.RC_OK)

def test_send_scp_request_to_nonexistent_host(self):
with self.assertRaises(SpinnmanTimeoutException):
board_config.set_up_nonexistent_board()
self.board_config.set_up_nonexistent_board()
connection = SCAMPConnection(
remote_host=board_config.remotehost)
remote_host=self.board_config.remotehost)
scp = ReadMemory(0, 0, 0, 256)
connection.send_scp_request(scp)
_, _, _, _ = connection.receive_scp_response(2)
Expand Down
3 changes: 1 addition & 2 deletions unittests/model_tests/test_iptag_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
from spinnman.board_test_configuration import BoardTestConfiguration
from spinnman.config_setup import unittest_setup

board_config = BoardTestConfiguration()


class TestIptag(unittest.TestCase):

def setUp(self):
unittest_setup()

def test_new_iptag(self):
board_config = BoardTestConfiguration()
board_config.set_up_remote_board()
ip = "8.8.8.8"
port = 1337
Expand Down
50 changes: 25 additions & 25 deletions unittests/test_transceiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from spinn_utilities.config_holder import set_config
from spinn_machine import virtual_machine
from spinnman.config_setup import unittest_setup
from spinnman.data import SpiNNManDataView
from spinnman.data.spinnman_data_writer import SpiNNManDataWriter
from spinnman.extended.extended_transceiver import ExtendedTransceiver
from spinnman.transceiver import Transceiver
Expand All @@ -29,7 +30,6 @@
import spinnman.extended.extended_transceiver as extended
from spinnman.board_test_configuration import BoardTestConfiguration

board_config = BoardTestConfiguration()
ver = 5 # Guess?


Expand All @@ -41,7 +41,9 @@ def __init__(
self.written_memory = list()

def get_machine_details(self):
return virtual_machine(8, 8)
version = SpiNNManDataView.get_machine_version()
width, height = version.board_shape
return virtual_machine(width, height)

def _update_machine(self):
self._machine = self.get_machine_details()
Expand All @@ -65,72 +67,70 @@ class TestTransceiver(unittest.TestCase):

def setUp(self):
unittest_setup()
set_config("Machine", "version", 5)
self.board_config = BoardTestConfiguration()

def test_create_new_transceiver_to_board(self):
board_config.set_up_remote_board()
self.board_config.set_up_remote_board()
connections = list()
connections.append(SCAMPConnection(
remote_host=board_config.remotehost))
remote_host=self.board_config.remotehost))
trans = transceiver.Transceiver(ver, connections=connections)
trans.close()

def test_create_new_transceiver_one_connection(self):
board_config.set_up_remote_board()
self.board_config.set_up_remote_board()
connections = set()
connections.add(SCAMPConnection(
remote_host=board_config.remotehost))
remote_host=self.board_config.remotehost))
with extended.ExtendedTransceiver(
ver, connections=connections) as trans:
assert trans.get_connections() == connections
assert trans._all_connections == connections

def test_create_new_transceiver_from_list_connections(self):
board_config.set_up_remote_board()
self.board_config.set_up_remote_board()
connections = list()
connections.append(SCAMPConnection(
remote_host=board_config.remotehost))
board_config.set_up_local_virtual_board()
connections.append(BootConnection(
remote_host=board_config.remotehost))
remote_host=self.board_config.remotehost))
connections.append(BootConnection(remote_host="127.0.0.1"))
with transceiver.Transceiver(ver, connections=connections) as trans:
instantiated_connections = trans.get_connections()
instantiated_connections = trans._all_connections

for connection in connections:
assert connection in instantiated_connections
# assert trans.get_connections() == connections

def test_retrieving_machine_details(self):
board_config.set_up_remote_board()
self.board_config.set_up_remote_board()
connections = list()
connections.append(SCAMPConnection(
remote_host=board_config.remotehost))
board_config.set_up_local_virtual_board()
connections.append(BootConnection(
remote_host=board_config.remotehost))
remote_host=self.board_config.remotehost))
connections.append(BootConnection(remote_host="127.0.0.1"))
with transceiver.Transceiver(ver, connections=connections) as trans:
SpiNNManDataWriter.mock().set_machine(trans.get_machine_details())
if board_config.board_version in (2, 3):
if self.board_config.board_version in (2, 3):
assert trans._get_machine_dimensions().width == 2
assert trans._get_machine_dimensions().height == 2
elif board_config.board_version in (4, 5):
elif self.board_config.board_version in (4, 5):
assert trans._get_machine_dimensions().width == 8
assert trans._get_machine_dimensions().height == 8
else:
size = trans._get_machine_dimensions()
print(f"Unknown board with size {size.width} x {size.height}")

assert trans.is_connected()
assert any(c.is_connected() for c in trans._scamp_connections)
print(trans._get_scamp_version())
print(trans.get_cpu_infos())

def test_boot_board(self):
board_config.set_up_remote_board()
self.board_config.set_up_remote_board()
with transceiver.create_transceiver_from_hostname(
board_config.remotehost, board_config.board_version) as trans:
# self.assertFalse(trans.is_connected())
self.board_config.remotehost,
self.board_config.board_version) as trans:
# self.assertFalse(trans.is_connected( unittest_setup()))
trans._boot_board()

def test_set_watch_dog(self):
set_config("Machine", "version", 5)
connections = []
connections.append(SCAMPConnection(remote_host=None))
tx = MockExtendedTransceiver(version=5, connections=connections)
Expand Down

0 comments on commit 5713976

Please sign in to comment.