From b6b3251c01899b8af8752ab5e18d93ecc11fc1ef Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Fri, 28 Jul 2023 16:05:38 +0100 Subject: [PATCH] protect methods --- spinnman/extended/extended_transceiver.py | 12 ++-- spinnman/transceiver.py | 86 ++++++++++------------- unittests/test_transceiver.py | 14 ++-- unittests/test_version.py | 14 ++-- 4 files changed, 56 insertions(+), 70 deletions(-) diff --git a/spinnman/extended/extended_transceiver.py b/spinnman/extended/extended_transceiver.py index 44b8178c3..f2120267f 100644 --- a/spinnman/extended/extended_transceiver.py +++ b/spinnman/extended/extended_transceiver.py @@ -585,7 +585,7 @@ def read_neighbour_memory(self, x, y, link, base_address, length, cpu=0): return process.read_link_memory( x, y, cpu, link, base_address, length) except Exception: - logger.info(self.__where_is_xy(x, y)) + logger.info(self._where_is_xy(x, y)) raise def _get_next_nearest_neighbour_id(self): @@ -689,7 +689,7 @@ def set_leds(self, x, y, cpu, led_states): process = SendSingleCommandProcess(self._scamp_connection_selector) process.execute(SetLED(x, y, cpu, led_states)) except Exception: - logger.info(self.__where_is_xy(x, y)) + logger.info(self._where_is_xy(x, y)) raise def free_sdram(self, x, y, base_address, app_id): @@ -710,7 +710,7 @@ def free_sdram(self, x, y, base_address, app_id): process = DeAllocSDRAMProcess(self._scamp_connection_selector) process.de_alloc_sdram(x, y, app_id, base_address) except Exception: - logger.info(self.__where_is_xy(x, y)) + logger.info(self._where_is_xy(x, y)) raise def free_sdram_by_app_id(self, x, y, app_id): @@ -735,7 +735,7 @@ def free_sdram_by_app_id(self, x, y, app_id): process.de_alloc_sdram(x, y, app_id) return process.no_blocks_freed except Exception: - logger.info(self.__where_is_xy(x, y)) + logger.info(self._where_is_xy(x, y)) raise def get_router_diagnostic_filter(self, x, y, position): @@ -776,7 +776,7 @@ def get_router_diagnostic_filter(self, x, y, position): response.data, response.offset)[0]) # pylint: disable=no-member except Exception: - logger.info(self.__where_is_xy(x, y)) + logger.info(self._where_is_xy(x, y)) raise @property @@ -826,5 +826,5 @@ def get_heap(self, x, y, heap=SystemVariableDefinition.sdram_heap_address): process = GetHeapProcess(self._scamp_connection_selector) return process.get_heap((x, y), heap) except Exception: - logger.info(self.__where_is_xy(x, y)) + logger.info(self._where_is_xy(x, y)) raise diff --git a/spinnman/transceiver.py b/spinnman/transceiver.py index 3e410781a..b3897a5e4 100644 --- a/spinnman/transceiver.py +++ b/spinnman/transceiver.py @@ -240,7 +240,7 @@ def __init__( # build connection selectors for the processes. self._bmp_connection_selectors = dict() self._scamp_connection_selector = \ - self._identify_connections(connections) + self.__identify_connections(connections) # A lock against single chip executions (entry is (x, y)) # The condition should be acquired before the locks are @@ -252,11 +252,11 @@ def __init__( self._n_chip_execute_locks = 0 # Check that the BMP connections are valid - self._check_bmp_connections() + self.__check_bmp_connections() self._machine_off = False - def __where_is_xy(self, x, y): + def _where_is_xy(self, x, y): """ Attempts to get where_is_x_y info from the machine @@ -275,7 +275,7 @@ def __where_is_xy(self, x, y): except Exception as ex: # pylint: disable=broad-except return str(ex) - def _identify_connections(self, connections): + def __identify_connections(self, connections): for conn in connections: # locate the only boot send conn @@ -299,7 +299,7 @@ def _identify_connections(self, connections): # update the transceiver with the conn selectors. return MostDirectConnectionSelector(self._scamp_connections) - def _check_bmp_connections(self): + def __check_bmp_connections(self): """ Check that the BMP connections are actually connected to valid BMPs. @@ -311,7 +311,7 @@ def _check_bmp_connections(self): # try to send a BMP sver to check if it responds as expected try: - version_info = self.get_scamp_version( + version_info = self._get_scamp_version( conn.chip_x, conn.chip_y, self._bmp_connection_selectors[conn.cabinet, conn.frame]) fail_version_name = version_info.name != _BMP_NAME @@ -369,7 +369,7 @@ def _check_connection( return None @contextmanager - def _flood_execute_lock(self): + def __flood_execute_lock(self): """ Get a lock for executing a flood fill of an executable. """ @@ -459,7 +459,7 @@ def discover_scamp_connections(self): return list() # Get the machine dimensions - dims = self.get_machine_dimensions() + dims = self._get_machine_dimensions() # Find all the new connections via the machine Ethernet-connected chips version = SpiNNManDataView.get_machine_version() @@ -504,7 +504,7 @@ def add_scamp_connections(self, connections): self._scamp_connection_selector = MostDirectConnectionSelector( self._scamp_connections) - def get_machine_dimensions(self): + def _get_machine_dimensions(self): """ Get the maximum chip X-coordinate and maximum chip Y-coordinate of the chips in the machine. @@ -547,10 +547,10 @@ def get_machine_details(self): If a response indicates an error during the exchange """ # Get the width and height of the machine - self.get_machine_dimensions() + self._get_machine_dimensions() # Get the coordinates of the boot chip - version_info = self.get_scamp_version() + version_info = self._get_scamp_version() # Get the details of all the chips get_machine_process = GetMachineProcess( @@ -566,7 +566,7 @@ def get_machine_details(self): logger.info(f"Detected {machine.summary_string()}") return machine - def get_scamp_version( + def _get_scamp_version( self, chip_x=AbstractSCPRequest.DEFAULT_DEST_X_COORD, chip_y=AbstractSCPRequest.DEFAULT_DEST_Y_COORD, connection_selector=None, n_retries=N_RETRIES): @@ -596,7 +596,7 @@ def get_scamp_version( process = GetVersionProcess(connection_selector, n_retries) return process.get_version(x=chip_x, y=chip_y, p=0) - def boot_board( + def _boot_board( self, number_of_boards=None, width=None, height=None, extra_boot_values=None): """ @@ -628,7 +628,7 @@ def boot_board( time.sleep(2.0) @staticmethod - def is_scamp_version_compabible(version): + def _is_scamp_version_compabible(version): """ Determine if the version of SCAMP is compatible with this transceiver. @@ -696,7 +696,7 @@ def ensure_board_is_ready( # start by powering up each BMP connection logger.info("Attempting to power on machine") - self.power_on_machine() + self._power_on_machine() # Sleep a bit to let things get going time.sleep(2.0) @@ -711,7 +711,7 @@ def ensure_board_is_ready( raise SpinnmanIOException( "Failed to communicate with the machine") if (version_info.name != _SCAMP_NAME or - not self.is_scamp_version_compabible( + not self._is_scamp_version_compabible( version_info.version_number)): raise SpinnmanIOException( f"The machine is currently booted with {version_info.name}" @@ -771,14 +771,14 @@ def _try_to_find_scamp_and_boot( current_tries_to_go = tries_to_go while version_info is None and current_tries_to_go > 0: try: - version_info = self.get_scamp_version(n_retries=BOOT_RETRIES) + version_info = self._get_scamp_version(n_retries=BOOT_RETRIES) if self.__is_default_destination(version_info): version_info = None time.sleep(0.1) except SpinnmanGenericProcessException as e: if isinstance(e.exception, SpinnmanTimeoutException): logger.info("Attempting to boot machine") - self.boot_board( + self._boot_board( number_of_boards, width, height, extra_boot_values) current_tries_to_go -= 1 elif isinstance(e.exception, SpinnmanIOException): @@ -788,7 +788,7 @@ def _try_to_find_scamp_and_boot( raise except SpinnmanTimeoutException: logger.info("Attempting to boot machine") - self.boot_board( + self._boot_board( number_of_boards, width, height, extra_boot_values) current_tries_to_go -= 1 except SpinnmanIOException as e: @@ -798,7 +798,7 @@ def _try_to_find_scamp_and_boot( # The last thing we tried was booting, so try again to get the version if version_info is None: with suppress(SpinnmanException): - version_info = self.get_scamp_version() + version_info = self._get_scamp_version() if self.__is_default_destination(version_info): version_info = None if version_info is not None: @@ -1058,7 +1058,7 @@ def execute_flood( If a response indicates an error during the exchange """ # Lock against other executable's - with self._flood_execute_lock(): + with self.__flood_execute_lock(): # Flood fill the system with the binary n_bytes, chksum = self.write_memory( 0, 0, _EXECUTABLE_ADDRESS, executable, n_bytes, @@ -1077,7 +1077,7 @@ def execute_flood( self._scamp_connection_selector) process.run(n_bytes, app_id, core_subsets, chksum, wait) - def power_on_machine(self): + def _power_on_machine(self): """ Power on the whole machine. @@ -1351,7 +1351,7 @@ def read_memory(self, x, y, base_address, length, cpu=0): process = ReadMemoryProcess(self._scamp_connection_selector) return process.read_memory(x, y, cpu, base_address, length) except Exception: - logger.info(self.__where_is_xy(x, y)) + logger.info(self._where_is_xy(x, y)) raise def read_word(self, x, y, base_address, cpu=0): @@ -1385,7 +1385,7 @@ def read_word(self, x, y, base_address, cpu=0): (value, ) = _ONE_WORD.unpack(data) return value except Exception: - logger.info(self.__where_is_xy(x, y)) + logger.info(self._where_is_xy(x, y)) raise def stop_application(self, app_id): @@ -1425,7 +1425,7 @@ def __log_where_is_info(self, cpu_infos): else: xys.add((cpu_info.x, cpu_info.y)) for (x, y) in xys: - logger.info(self.__where_is_xy(x, y)) + logger.info(self._where_is_xy(x, y)) def wait_for_cores_to_be_in_state( self, all_core_subsets, app_id, cpu_states, timeout=None, @@ -1547,7 +1547,7 @@ def send_signal(self, app_id, signal): process = SendSingleCommandProcess(self._scamp_connection_selector) process.execute(SendSignal(app_id, signal)) - def locate_spinnaker_connection_for_board_address(self, board_address): + def _locate_spinnaker_connection_for_board_address(self, board_address): """ Find a connection that matches the given board IP address. @@ -1625,7 +1625,7 @@ def __get_connection_list(self, connection=None, board_address=None): elif board_address is None: return self._scamp_connections - connection = self.locate_spinnaker_connection_for_board_address( + connection = self._locate_spinnaker_connection_for_board_address( board_address) if connection is None: return [] @@ -1754,7 +1754,7 @@ def malloc_sdram(self, x, y, size, app_id, tag=None): process.malloc_sdram(x, y, size, app_id, tag) return process.base_address except Exception: - logger.info(self.__where_is_xy(x, y)) + logger.info(self._where_is_xy(x, y)) raise def load_multicast_routes(self, x, y, routes, app_id): @@ -1784,7 +1784,7 @@ def load_multicast_routes(self, x, y, routes, app_id): self._scamp_connection_selector) process.load_routes(x, y, routes, app_id) except Exception: - logger.info(self.__where_is_xy(x, y)) + logger.info(self._where_is_xy(x, y)) raise def load_fixed_route(self, x, y, fixed_route, app_id): @@ -1814,7 +1814,7 @@ def load_fixed_route(self, x, y, fixed_route, app_id): self._scamp_connection_selector) process.load_fixed_route(x, y, fixed_route, app_id) except Exception: - logger.info(self.__where_is_xy(x, y)) + logger.info(self._where_is_xy(x, y)) raise def read_fixed_route(self, x, y, app_id): @@ -1835,7 +1835,7 @@ def read_fixed_route(self, x, y, app_id): self._scamp_connection_selector) return process.read_fixed_route(x, y, app_id) except Exception: - logger.info(self.__where_is_xy(x, y)) + logger.info(self._where_is_xy(x, y)) raise def get_multicast_routes(self, x, y, app_id=None): @@ -1867,7 +1867,7 @@ def get_multicast_routes(self, x, y, app_id=None): self._scamp_connection_selector, app_id) return process.get_routes(x, y, base_address) except Exception: - logger.info(self.__where_is_xy(x, y)) + logger.info(self._where_is_xy(x, y)) raise def clear_multicast_routes(self, x, y): @@ -1889,7 +1889,7 @@ def clear_multicast_routes(self, x, y): process = SendSingleCommandProcess(self._scamp_connection_selector) process.execute(RouterClear(x, y)) except Exception: - logger.info(self.__where_is_xy(x, y)) + logger.info(self._where_is_xy(x, y)) raise def get_router_diagnostics(self, x, y): @@ -1916,7 +1916,7 @@ def get_router_diagnostics(self, x, y): self._scamp_connection_selector) return process.get_router_diagnostics(x, y) except Exception: - logger.info(self.__where_is_xy(x, y)) + logger.info(self._where_is_xy(x, y)) raise def set_router_diagnostic_filter(self, x, y, position, diagnostic_filter): @@ -1951,7 +1951,7 @@ def set_router_diagnostic_filter(self, x, y, position, diagnostic_filter): self.__set_router_diagnostic_filter( x, y, position, diagnostic_filter) except Exception: - logger.info(self.__where_is_xy(x, y)) + logger.info(self._where_is_xy(x, y)) raise def __set_router_diagnostic_filter( @@ -1999,7 +1999,7 @@ def clear_router_diagnostic_counters(self, x, y): process.execute(WriteMemory( x, y, 0xf100002c, _ONE_WORD.pack(0xFFFFFFFF))) except Exception: - logger.info(self.__where_is_xy(x, y)) + logger.info(self._where_is_xy(x, y)) raise def close(self): @@ -2013,20 +2013,6 @@ def close(self): for connection in self._all_connections: connection.close() - @property - def bmp_connection(self): - """ - The BMP connections. - - .. warning:: - This property is currently deprecated and likely to be removed. - - :rtype: dict(tuple(int,int),MostDirectConnectionSelector) - """ - warn_once(logger, "The bmp_connection property is deprecated and " - "likely to be removed.") - return self._bmp_connection_selectors - def control_sync(self, do_sync): """ Control the synchronisation of the chips. diff --git a/unittests/test_transceiver.py b/unittests/test_transceiver.py index a6c1f3b9d..52c31486c 100644 --- a/unittests/test_transceiver.py +++ b/unittests/test_transceiver.py @@ -110,17 +110,17 @@ def test_retrieving_machine_details(self): with transceiver.Transceiver(ver, connections=connections) as trans: SpiNNManDataWriter.mock().set_machine(trans.get_machine_details()) if board_config.board_version in (2, 3): - assert trans.get_machine_dimensions().width == 2 - assert trans.get_machine_dimensions().height == 2 + assert trans._get_machine_dimensions().width == 2 + assert trans._get_machine_dimensions().height == 2 elif board_config.board_version in (4, 5): - assert trans.get_machine_dimensions().width == 8 - assert trans.get_machine_dimensions().height == 8 + assert trans._get_machine_dimensions().width == 8 + assert trans._get_machine_dimensions().height == 8 else: - size = trans.get_machine_dimensions() + size = trans._get_machine_dimensions() print(f"Unknown board with size {size.width} x {size.height}") assert trans.is_connected() - print(trans.get_scamp_version()) + print(trans._get_scamp_version()) print(trans.get_cpu_infos()) def test_boot_board(self): @@ -128,7 +128,7 @@ def test_boot_board(self): with transceiver.create_transceiver_from_hostname( board_config.remotehost, board_config.board_version) as trans: # self.assertFalse(trans.is_connected()) - trans.boot_board() + trans._boot_board() def test_set_watch_dog(self): connections = [] diff --git a/unittests/test_version.py b/unittests/test_version.py index fdac35f8f..c8f42fc87 100644 --- a/unittests/test_version.py +++ b/unittests/test_version.py @@ -28,31 +28,31 @@ def setUp(self): unittest_setup() def test_version_same(self): - self.assertTrue(Transceiver.is_scamp_version_compabible(( + self.assertTrue(Transceiver._is_scamp_version_compabible(( _SCAMP_VERSION[0], _SCAMP_VERSION[1], _SCAMP_VERSION[2]))) def test_major_version_too_big(self): - self.assertFalse(Transceiver.is_scamp_version_compabible(( + self.assertFalse(Transceiver._is_scamp_version_compabible(( _SCAMP_VERSION[0] + 1, 0, 0))) def test_major_version_too_small(self): - self.assertFalse(Transceiver.is_scamp_version_compabible(( + self.assertFalse(Transceiver._is_scamp_version_compabible(( _SCAMP_VERSION[0] - 1, 0, 0))) def test_minor_version_bigger(self): - self.assertTrue(Transceiver.is_scamp_version_compabible(( + self.assertTrue(Transceiver._is_scamp_version_compabible(( _SCAMP_VERSION[0], _SCAMP_VERSION[1] + 1, _SCAMP_VERSION[2]))) def test_minor_version_smaller(self): - self.assertFalse(Transceiver.is_scamp_version_compabible(( + self.assertFalse(Transceiver._is_scamp_version_compabible(( _SCAMP_VERSION[0], _SCAMP_VERSION[1] - 1, _SCAMP_VERSION[2]))) def test_patch_version_bigger(self): - self.assertTrue(Transceiver.is_scamp_version_compabible(( + self.assertTrue(Transceiver._is_scamp_version_compabible(( _SCAMP_VERSION[0], _SCAMP_VERSION[1], _SCAMP_VERSION[2] + 1))) def test_patch_version_smaller(self): - self.assertFalse(Transceiver.is_scamp_version_compabible(( + self.assertFalse(Transceiver._is_scamp_version_compabible(( _SCAMP_VERSION[0], _SCAMP_VERSION[1], _SCAMP_VERSION[2] - 1))) def test_compare_versions(self):