From de62f49ad4e904270fe8186b2578748c13a0da9c Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Thu, 3 Aug 2023 06:30:28 +0100 Subject: [PATCH 1/2] fix tests that use board_test_configuration --- quick_tests/quick_tests.py | 2 +- spinnman/board_test_configuration.cfg | 9 ---- spinnman/board_test_configuration.py | 42 ++++++++-------- spinnman/get_cores_in_run_state.py | 3 +- .../connection_tests/test_udp_connection.py | 18 +++---- unittests/model_tests/test_iptag_model.py | 2 +- unittests/test_transceiver.py | 49 ++++++++++--------- 7 files changed, 60 insertions(+), 65 deletions(-) delete mode 100644 spinnman/board_test_configuration.cfg diff --git a/quick_tests/quick_tests.py b/quick_tests/quick_tests.py index 89ae9315f..f28772a71 100644 --- a/quick_tests/quick_tests.py +++ b/quick_tests/quick_tests.py @@ -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() @@ -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, diff --git a/spinnman/board_test_configuration.cfg b/spinnman/board_test_configuration.cfg deleted file mode 100644 index b19bb182a..000000000 --- a/spinnman/board_test_configuration.cfg +++ /dev/null @@ -1,9 +0,0 @@ -[Machine] -machineName = spinn-4.cs.man.ac.uk -bmp_names = spinn-4c.cs.man.ac.uk -version = 5 - -#machineName = 192.168.240.253 -#version = 2 -#bmp_names = None -auto_detect_bmp = False diff --git a/spinnman/board_test_configuration.py b/spinnman/board_test_configuration.py index b936c8603..77d1883ee 100644 --- a/spinnman/board_test_configuration.py +++ b/spinnman/board_test_configuration.py @@ -17,6 +17,7 @@ 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 @@ -30,44 +31,45 @@ class BoardTestConfiguration(object): def __init__(self): - self.localhost = None + #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.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 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: + raise unittest.SkipTest("None of the test boards reachable") + if self.bmp_names == "None": self.bmp_names = None else: + # it always was None but this is what to do if not self.bmp_names = [BMPConnectionData( 0, 0, 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] 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 diff --git a/spinnman/get_cores_in_run_state.py b/spinnman/get_cores_in_run_state.py index 5b4374029..075cb166a 100644 --- a/spinnman/get_cores_in_run_state.py +++ b/spinnman/get_cores_in_run_state.py @@ -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? @@ -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( diff --git a/unittests/connection_tests/test_udp_connection.py b/unittests/connection_tests/test_udp_connection.py index ad4efa069..d3ce2663e 100644 --- a/unittests/connection_tests/test_udp_connection.py +++ b/unittests/connection_tests/test_udp_connection.py @@ -21,18 +21,18 @@ 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) @@ -43,18 +43,18 @@ 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() @@ -62,9 +62,9 @@ def test_scp_read_memory_request_and_response_board(self): 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) diff --git a/unittests/model_tests/test_iptag_model.py b/unittests/model_tests/test_iptag_model.py index 1ffcca225..c45b9fc49 100644 --- a/unittests/model_tests/test_iptag_model.py +++ b/unittests/model_tests/test_iptag_model.py @@ -17,7 +17,6 @@ from spinnman.board_test_configuration import BoardTestConfiguration from spinnman.config_setup import unittest_setup -board_config = BoardTestConfiguration() class TestIptag(unittest.TestCase): @@ -26,6 +25,7 @@ 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 diff --git a/unittests/test_transceiver.py b/unittests/test_transceiver.py index 52c31486c..2926f314e 100644 --- a/unittests/test_transceiver.py +++ b/unittests/test_transceiver.py @@ -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 @@ -29,7 +30,6 @@ import spinnman.extended.extended_transceiver as extended from spinnman.board_test_configuration import BoardTestConfiguration -board_config = BoardTestConfiguration() ver = 5 # Guess? @@ -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() @@ -63,71 +65,70 @@ class MockExtendedTransceiver(MockWriteTransceiver, ExtendedTransceiver): 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): From d4feab026a0e1732b9ffea7da9c6f4d6170aee66 Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Thu, 3 Aug 2023 07:29:09 +0100 Subject: [PATCH 2/2] comment out import for commented out code --- spinnman/board_test_configuration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spinnman/board_test_configuration.py b/spinnman/board_test_configuration.py index 5e38edaf7..329c625fd 100644 --- a/spinnman/board_test_configuration.py +++ b/spinnman/board_test_configuration.py @@ -15,7 +15,7 @@ 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: