diff --git a/pyproject.toml b/pyproject.toml index b2bf2c79..f6ad0662 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,4 +14,8 @@ [build-system] requires = ["setuptools"] -build-backend = "setuptools.build_meta" \ No newline at end of file +build-backend = "setuptools.build_meta" + +[[tool.mypy.overrides]] +module = ["parameterized"] +ignore_missing_imports = true diff --git a/setup.cfg b/setup.cfg index 356ae5dc..f3e5baaf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -64,4 +64,5 @@ test = testfixtures httpretty != 1.0.0 deepdiff + parameterized diff --git a/spinn_machine/spinn_machine.cfg b/spinn_machine/spinn_machine.cfg index 313b0bab..12d9ce24 100644 --- a/spinn_machine/spinn_machine.cfg +++ b/spinn_machine/spinn_machine.cfg @@ -16,8 +16,6 @@ version = None * This replaces deprecated "width" and "height" options * "versions" option is for testing only and picks a version based on python version # Used Instead of version if multiple versions should be tested! -versions = None -@versions = Testing Option. Picks a valid version based on python version. Requires [virtual_board](virtual_board) width = None @width = Deprecated use [version](version). Width for a virtual machine. If used requires [height](height) and [virtual_board](virtual_board) diff --git a/spinn_machine/version/__init__.py b/spinn_machine/version/__init__.py index 52d9d6d9..cbf4aead 100644 --- a/spinn_machine/version/__init__.py +++ b/spinn_machine/version/__init__.py @@ -12,7 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .version_factory import (FIVE, SPIN2_1CHIP, SPIN2_48CHIP, THREE, - version_factory) +from .version_factory import ( + ALL_BOARD_TYPES, BIG_BOARD_TYPES, FOUR_PLUS_BOARD_TYPES, + FPGA_BOARD_TYPES, MANY_BOARD_TYPES, + FIVE, SPIN2_1CHIP, SPIN2_48CHIP, THREE, version_factory) -__all__ = ["FIVE", "SPIN2_1CHIP", "SPIN2_48CHIP", "THREE", "version_factory"] +__all__ = ["ALL_BOARD_TYPES", "BIG_BOARD_TYPES", "FOUR_PLUS_BOARD_TYPES", + "FPGA_BOARD_TYPES", "MANY_BOARD_TYPES", "version_factory", + "FIVE", "SPIN2_1CHIP", "SPIN2_48CHIP", "THREE"] diff --git a/spinn_machine/version/version_factory.py b/spinn_machine/version/version_factory.py index e15500ae..e3a5aa1a 100644 --- a/spinn_machine/version/version_factory.py +++ b/spinn_machine/version/version_factory.py @@ -14,16 +14,16 @@ from __future__ import annotations import logging -import sys from typing import Optional, TYPE_CHECKING +import os from typing_extensions import Never from spinn_utilities.config_holder import ( - get_config_bool, get_config_int_or_none, get_config_str_or_none) + get_config_bool, get_config_int_or_none, get_config_str_or_none, + has_config_option) from spinn_utilities.log import FormatAdapter from spinn_machine.exceptions import SpinnMachineException -from .version_strings import VersionStrings if TYPE_CHECKING: from .abstract_version import AbstractVersion @@ -36,6 +36,19 @@ SPIN2_1CHIP = 201 SPIN2_48CHIP = 248 +ALL_BOARD_TYPES = [["THREE", str(THREE)], ["FIVE", str(FIVE)], + ["SPIN2_1CHIP", str(SPIN2_1CHIP)], + ["SPIN2_48CHIP", str(SPIN2_48CHIP)]] +FOUR_PLUS_BOARD_TYPES = [["THREE", THREE], ["FIVE", str(FIVE)], + ["SPIN2_48CHIP", str(SPIN2_48CHIP)]] +BIG_BOARD_TYPES = [["FIVE", str(FIVE)], + ["SPIN2_48CHIP", str(SPIN2_48CHIP)]] +FPGA_BOARD_TYPES = [["FIVE", str(FIVE)]] +if os.environ.get("SPINNAKER_TEST_ALL") == "true": + MANY_BOARD_TYPES = ALL_BOARD_TYPES +else: + MANY_BOARD_TYPES = BIG_BOARD_TYPES + def version_factory() -> AbstractVersion: """ @@ -86,16 +99,9 @@ def version_factory() -> AbstractVersion: def _get_cfg_version() -> Optional[int]: version = get_config_int_or_none("Machine", "version") - versions = get_config_str_or_none("Machine", "versions") - if versions is not None: - if version is not None: - raise SpinnMachineException( - f"Both {version=} and {versions=} found in cfg") - vs = VersionStrings.from_string(versions) - options = vs.options - # Use the fact that we run actions against different python versions - minor = sys.version_info.minor - version = options[minor % len(options)] + if has_config_option("Machine", "versions"): + raise SpinnMachineException( + "versions in cfg is no longer supported.") if version is None: logger.warning( "The cfg has no version. This is deprecated! Please add a version") diff --git a/spinn_machine/version/version_strings.py b/spinn_machine/version/version_strings.py deleted file mode 100644 index 9517dc75..00000000 --- a/spinn_machine/version/version_strings.py +++ /dev/null @@ -1,99 +0,0 @@ -# Copyright (c) 2024 The University of Manchester -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from enum import Enum -from typing import List, Tuple -from typing_extensions import Self -from spinn_machine.exceptions import SpinnMachineException - - -class VersionStrings(Enum): - """ - A description of strings in cfg settings to say test versions - - As additional Versions are added this should allow easy testing of these - as far as possible. - """ - - ANY = (1, "Any", [3, 5, 201, 248]) - FOUR_PLUS = (2, "Four plus", [3, 5, 248]) - # To test stuff with more than four chips. - BIG = (3, "Big", [5, 248]) - # Tests that specifically require 8 by 8 board(s) - # Could be changed but not worth the effort until needed - EIGHT_BY_EIGHT = (5, "eight by eigth", [5, 248]) - # Tests for 8 by 8 boards with FPGAs defined - WITH_FPGAS = (6, "with fpgas", [5]) - - def __new__(cls, *args: Tuple[int, str, List[int]], **kwds: None) -> Self: - vs = object.__new__(cls) - vs._value_ = args[0] - return vs - - def __init__(self, value: int, text: str, versions: List[int]): - """ - :param value: enum ID for this version - :param text: label for this enum - :param versions: machine versions that this group includes - """ - # ignore the first param since it's already set by __new__ - _ = value - self.text = text - self._versions = versions - - def __str__(self) -> str: - return self.text - - @property - def short_str(self) -> str: - """ - The text but in a shortened version - - This makes the text lower case and removes some special characters - """ - return self.shorten(self.text) - - # this makes sure that the description is read-only - @property - def options(self) -> List[int]: - """ - The list of the versions covered by this string - - This list can grow as new versions are added - """ - return self._versions - - @classmethod - def shorten(cls, value: str) -> str: - """ - Makes the String lower case and removes some special characters - - :param value: original string - :returns: original in lower case and without special characters - """ - return value.lower().replace("_", "").replace("-", "").replace(" ", "") - - @classmethod - def from_string(cls, value: str) -> "VersionStrings": - """ - Gets a VersionString object from a String - - :param value: label - :returns: VersionStrings Enum with this label - """ - value_short = cls.shorten(value) - for vs in cls: - if value_short == vs.short_str: - return vs - raise SpinnMachineException(f"No version for {value=}") diff --git a/unittests/data/test_data.py b/unittests/data/test_data.py index 3644bcb7..19cabc69 100644 --- a/unittests/data/test_data.py +++ b/unittests/data/test_data.py @@ -12,16 +12,18 @@ # See the License for the specific language governing permissions and # limitations under the License. +from parameterized import parameterized import unittest + from spinn_utilities.config_holder import set_config from spinn_utilities.exceptions import (ConfigException, DataNotYetAvialable) + from spinn_machine import virtual_machine from spinn_machine.config_setup import unittest_setup from spinn_machine.data import MachineDataView from spinn_machine.data.machine_data_writer import MachineDataWriter from spinn_machine.exceptions import SpinnMachineException -from spinn_machine.version import FIVE, THREE, SPIN2_48CHIP -from spinn_machine.version.version_strings import VersionStrings +from spinn_machine.version import BIG_BOARD_TYPES, FIVE, THREE, SPIN2_48CHIP class TestSimulatorData(unittest.TestCase): @@ -59,8 +61,9 @@ def test_machine(self) -> None: writer.set_machine("bacon") # type: ignore[arg-type] self.assertTrue(MachineDataView.has_machine()) - def test_where_is_mocked(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) # needs multiple boards + def test_where_is_mocked(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) writer = MachineDataWriter.mock() self.assertEqual( "No Machine created yet", @@ -77,8 +80,9 @@ def test_where_is_mocked(self) -> None: "global chip 2, 8 on 127.0.0.0 is chip 6, 4 on 127.0.8.4", MachineDataView.where_is_chip(machine[2, 8])) - def test_where_is_setup(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) # Needs multiple boards + def test_where_is_setup(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) writer = MachineDataWriter.setup() self.assertEqual( "No Machine created yet", @@ -138,43 +142,6 @@ def test_v_to_p_spin2(self) -> None: self.assertEqual("", writer.get_physical_string((1, 2), 234)) - def test_mock_any(self) -> None: - # Should work with any version - set_config("Machine", "versions", VersionStrings.ANY.text) - # check there is a value not what it is - machine = MachineDataView.get_machine() - self.assertGreaterEqual(machine.n_chips, 1) - - def test_mock_4_or_more(self) -> None: - # Should work with any version that has 4 plus Chips - set_config("Machine", "versions", VersionStrings.FOUR_PLUS.text) - # check there is a value not what it is - machine = MachineDataView.get_machine() - self.assertGreaterEqual(machine.n_chips, 4) - - def test_mock_big(self) -> None: - # Should work with any version - set_config("Machine", "versions", VersionStrings.BIG.text) - # check there is a value not what it is - machine = MachineDataView.get_machine() - self.assertGreaterEqual(machine.n_chips, 48) - - def test_mock3(self) -> None: - # Should work with any version - set_config("Machine", "version", "3") - # check there is a value not what it is - MachineDataView.get_machine() - - def test_mock5(self) -> None: - set_config("Machine", "version", "5") - # check there is a value not what it is - MachineDataView.get_machine() - - def test_mock201(self) -> None: - set_config("Machine", "version", "201") - # check there is a value not what it is - MachineDataView.get_machine() - def test_get_monitors(self) -> None: writer = MachineDataWriter.setup() self.assertEqual(0, MachineDataView.get_all_monitor_cores()) diff --git a/unittests/test_chip.py b/unittests/test_chip.py index 5cbc9d22..5eb0c0ab 100644 --- a/unittests/test_chip.py +++ b/unittests/test_chip.py @@ -15,18 +15,15 @@ from typing import Optional import unittest -from spinn_utilities.config_holder import set_config from spinn_utilities.ordered_set import OrderedSet from spinn_machine import Link, Router, Chip from spinn_machine.config_setup import unittest_setup -from spinn_machine.version.version_strings import VersionStrings class TestingChip(unittest.TestCase): def setUp(self) -> None: unittest_setup() - set_config("Machine", "versions", VersionStrings.ANY.text) self._x = 0 self._y = 1 diff --git a/unittests/test_ignore_cores.py b/unittests/test_ignore_cores.py index 4bbd903c..e3ecf9e6 100644 --- a/unittests/test_ignore_cores.py +++ b/unittests/test_ignore_cores.py @@ -13,15 +13,18 @@ # limitations under the License. import unittest + +from parameterized import parameterized + from spinn_utilities.config_holder import set_config from spinn_utilities.exceptions import ConfigException + from spinn_machine.config_setup import unittest_setup from spinn_machine.exceptions import SpinnMachineException from spinn_machine.ignores import IgnoreChip, IgnoreCore, IgnoreLink -from spinn_machine.version import SPIN2_1CHIP +from spinn_machine.version import SPIN2_1CHIP, MANY_BOARD_TYPES from spinn_machine.version.version_201 import Version201 from spinn_machine.version.version_5 import Version5 -from spinn_machine.version.version_strings import VersionStrings class TestDownCores(unittest.TestCase): @@ -29,8 +32,9 @@ class TestDownCores(unittest.TestCase): def setUp(self) -> None: unittest_setup() - def test_bad_ignores(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(MANY_BOARD_TYPES) + def test_bad_ignores(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) try: IgnoreChip.parse_string("4,4,3,4:6,6,ignored_ip") @@ -50,8 +54,9 @@ def test_bad_ignores(self) -> None: except Exception as ex: self.assertTrue("downed_link" in str(ex)) - def test_down_cores_bad_string(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(MANY_BOARD_TYPES) + def test_down_cores_bad_string(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) with self.assertRaises(ConfigException): IgnoreCore.parse_string("4,4,bacon") diff --git a/unittests/test_json_machine.py b/unittests/test_json_machine.py index 0205c3ba..28f7cbaf 100644 --- a/unittests/test_json_machine.py +++ b/unittests/test_json_machine.py @@ -12,17 +12,21 @@ # See the License for the specific language governing permissions and # limitations under the License. +from parameterized import parameterized from tempfile import mktemp import unittest + + from spinn_utilities.config_holder import set_config +from spinn_utilities.ordered_set import OrderedSet + from spinn_machine.virtual_machine import ( virtual_machine, virtual_machine_by_boards, virtual_machine_by_min_size) from spinn_machine.data.machine_data_writer import MachineDataWriter from spinn_machine.config_setup import unittest_setup from spinn_machine.json_machine import (machine_from_json, to_json_path) -from spinn_machine.version import (FIVE, SPIN2_1CHIP, THREE) -from spinn_machine.version.version_strings import VersionStrings -from spinn_utilities.ordered_set import OrderedSet +from spinn_machine.version import (BIG_BOARD_TYPES, FOUR_PLUS_BOARD_TYPES, + FIVE, SPIN2_1CHIP, THREE) class TestJsonMachine(unittest.TestCase): @@ -69,8 +73,9 @@ def test_json_version_201(self) -> None: for vchip, jchip in zip(vm, jm): self.assertEqual(str(vchip), str(jchip)) - def test_json_hole(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) # Needs a large board + def test_json_hole(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) set_config("Machine", "down_chips", "3,3") writer = MachineDataWriter.mock() vm = virtual_machine_by_min_size(5, 5) @@ -84,8 +89,9 @@ def test_json_hole(self) -> None: for vchip, jchip in zip(vm, jm): self.assertEqual(str(vchip), str(jchip)) - def test_exceptions(self) -> None: - set_config("Machine", "versions", VersionStrings.FOUR_PLUS.text) + @parameterized.expand(FOUR_PLUS_BOARD_TYPES) + def test_exceptions(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) writer = MachineDataWriter.mock() vm = virtual_machine_by_boards(1) writer.set_machine(vm) @@ -104,8 +110,9 @@ def test_exceptions(self) -> None: vchip10 = jm[1, 0] self.assertEqual(vchip10.tag_ids, chip10.tag_ids) - def test_two_monitors(self) -> None: - set_config("Machine", "versions", VersionStrings.FOUR_PLUS.text) + @parameterized.expand(FOUR_PLUS_BOARD_TYPES) + def test_two_monitors(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) vm = virtual_machine_by_boards(1) MachineDataWriter.mock().set_machine(vm) for chip in vm.chips: @@ -120,8 +127,9 @@ def test_two_monitors(self) -> None: for vchip, jchip in zip(vm, jm): self.assertEqual(str(vchip), str(jchip)) - def test_ethernet_exceptions(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) # Needs board with Ethernet + def test_ethernet_exceptions(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) vm = virtual_machine_by_boards(2) MachineDataWriter.mock().set_machine(vm) eth2 = vm.ethernet_connected_chips[1] diff --git a/unittests/test_machine.py b/unittests/test_machine.py index 2e92a0f3..8deb69b4 100644 --- a/unittests/test_machine.py +++ b/unittests/test_machine.py @@ -15,13 +15,15 @@ """ test for testing the python representation of a spinnaker machine """ +from parameterized import parameterized + from testfixtures import LogCapture # type: ignore[import] import unittest from spinn_utilities.config_holder import set_config from spinn_utilities.testing import log_checker from spinn_machine import Chip, Link, Machine, Router -from spinn_machine.version import FIVE -from spinn_machine.version.version_strings import VersionStrings +from spinn_machine.version import ( + ALL_BOARD_TYPES, BIG_BOARD_TYPES, FOUR_PLUS_BOARD_TYPES, FIVE) from spinn_machine.virtual_machine import ( virtual_machine_by_boards, virtual_machine_by_min_size) from spinn_machine.config_setup import unittest_setup @@ -144,11 +146,12 @@ def test_summary(self) -> None: "Not all Chips had the same n_router_tables. " "The counts where Counter({456: 1, 321: 1}).") - def test_chip_already_exists(self) -> None: + @parameterized.expand(ALL_BOARD_TYPES) + def test_chip_already_exists(self, _: str, ver_num: str) -> None: """ check that adding a chip that already exists causes an error """ - set_config("Machine", "versions", VersionStrings.ANY.text) + set_config("Machine", "version", ver_num) machine = virtual_machine_by_boards(1) with self.assertRaises(SpinnMachineAlreadyExistsException): machine.add_chip(Chip( @@ -156,23 +159,25 @@ def test_chip_already_exists(self) -> None: self._nearest_ethernet_chip[0], self._nearest_ethernet_chip[1], self._ip)) - def test_machine_get_chip_at(self) -> None: + @parameterized.expand(FOUR_PLUS_BOARD_TYPES) + def test_machine_get_chip_at(self, _: str, ver_num: str) -> None: """ test the get_chip_at function from the machine with a valid request """ - set_config("Machine", "versions", VersionStrings.FOUR_PLUS.text) + set_config("Machine", "version", ver_num) new_machine = virtual_machine_by_min_size(2, 2) self.assertEqual(1, new_machine[1, 0].x) self.assertEqual(0, new_machine[1, 0].y) self.assertEqual(0, new_machine[0, 1].x) self.assertEqual(1, new_machine[0, 1].y) - def test_machine_big_x(self) -> None: + @parameterized.expand(ALL_BOARD_TYPES) + def test_machine_big_x(self, _: str, ver_num: str) -> None: """ test the add_chips method of the machine chips outside size should produce an error """ - set_config("Machine", "versions", VersionStrings.ANY.text) + set_config("Machine", "version", ver_num) version = MachineDataView.get_machine_version() width, height = version.board_shape # create an empty Machine @@ -186,12 +191,13 @@ def test_machine_big_x(self) -> None: except SpinnMachineException as ex: self.assertIn(f"has an x larger than width {width}", str(ex)) - def test_machine_big_y(self) -> None: + @parameterized.expand(ALL_BOARD_TYPES) + def test_machine_big_y(self, _: str, ver_num: str) -> None: """ test the add_chips method of the machine chips outside size should produce an error """ - set_config("Machine", "versions", VersionStrings.ANY.text) + set_config("Machine", "version", ver_num) version = MachineDataView.get_machine_version() width, height = version.board_shape # create an empty Machine @@ -205,41 +211,46 @@ def test_machine_big_y(self) -> None: except SpinnMachineException as ex: self.assertIn(f"has a y larger than height {height}", str(ex)) - def test_machine_get_chip_at_invalid_location(self) -> None: + @parameterized.expand(ALL_BOARD_TYPES) + def test_machine_get_chip_at_invalid_location( + self, _: str, ver_num: str) -> None: """ test the machines get_chip_at function with a location thats invalid, should return None and not produce an error """ - set_config("Machine", "versions", VersionStrings.ANY.text) + set_config("Machine", "version", ver_num) version = MachineDataView.get_machine_version() new_machine = virtual_machine_by_boards(1) width, height = version.board_shape self.assertEqual(None, new_machine.get_chip_at(width + 2, height // 2)) - def test_machine_is_chip_at_true(self) -> None: + @parameterized.expand(ALL_BOARD_TYPES) + def test_machine_is_chip_at_true(self, _: str, ver_num: str) -> None: """ test the is_chip_at function of the machine with a position to request which does indeed contain a chip """ - set_config("Machine", "versions", VersionStrings.ANY.text) + set_config("Machine", "version", ver_num) version = MachineDataView.get_machine_version() new_machine = virtual_machine_by_boards(1) width, height = version.board_shape self.assertTrue(new_machine.is_chip_at(width // 2, height // 2)) - def test_machine_is_chip_at_false(self) -> None: + @parameterized.expand(ALL_BOARD_TYPES) + def test_machine_is_chip_at_false(self, _: str, ver_num: str) -> None: """ test the is_chip_at function of the machine with a position to request which does not contain a chip """ - set_config("Machine", "versions", VersionStrings.ANY.text) + set_config("Machine", "version", ver_num) version = MachineDataView.get_machine_version() new_machine = virtual_machine_by_boards(1) width, height = version.board_shape self.assertFalse(new_machine.is_chip_at(width + 2, height // 2)) - def test_machine_get_chips_on_board(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) # Needs many boards + def test_machine_get_chips_on_board(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) new_machine = virtual_machine_by_boards(3) version = MachineDataView.get_machine_version() for eth_chip in new_machine._ethernet_connected_chips: @@ -252,13 +263,14 @@ def test_machine_get_chips_on_board(self) -> None: with self.assertRaises(KeyError): new_machine.get_fpga_link_with_id(3, 3) - def test_x_y_over_link(self) -> None: + @parameterized.expand(BIG_BOARD_TYPES) # Needs multiple boards + def test_x_y_over_link(self, _: str, ver_num: str) -> None: """ Test the x_y with each wrap around. Notice that the function only does the math not validate the values. """ - set_config("Machine", "versions", VersionStrings.EIGHT_BY_EIGHT.text) + set_config("Machine", "version", ver_num) # full wrap around machine = MachineDataView.get_machine_version().create_machine(24, 24) self.assertEqual(machine.xy_over_link(0, 0, 4), (23, 23)) @@ -280,13 +292,14 @@ def test_x_y_over_link(self) -> None: self.assertEqual(machine.xy_over_link(15, 23, 1), (16, 0)) self.assertEqual(machine.wrap, "VerWrap") - def test_get_global_xy(self) -> None: + @parameterized.expand(BIG_BOARD_TYPES) # Needs a large board + def test_get_global_xy(self, _: str, ver_num: str) -> None: """ Test get_global_xy with each wrap around. Notice that the function only does the math not validate the values. """ - set_config("Machine", "versions", VersionStrings.EIGHT_BY_EIGHT.text) + set_config("Machine", "version", ver_num) # full wrap around machine = MachineDataView.get_machine_version().create_machine(24, 24) self.assertEqual(machine.get_global_xy(1, 4, 4, 20), (5, 0)) @@ -304,8 +317,9 @@ def test_get_global_xy(self) -> None: self.assertEqual(machine.get_global_xy(1, 4, 4, 20), (5, 0)) self.assertEqual(machine.get_global_xy(5, 0, 20, 4), (25, 4)) - def test_no_boot(self) -> None: - set_config("Machine", "versions", VersionStrings.ANY.text) + @parameterized.expand(ALL_BOARD_TYPES) + def test_no_boot(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) version = MachineDataView.get_machine_version() width, height = version.board_shape # create an empty Machine @@ -313,8 +327,9 @@ def test_no_boot(self) -> None: with self.assertRaises(SpinnMachineException): machine.validate() - def test_negative_x(self) -> None: - set_config("Machine", "versions", VersionStrings.ANY.text) + @parameterized.expand(ALL_BOARD_TYPES) + def test_negative_x(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) version = MachineDataView.get_machine_version() width, height = version.board_shape # create an empty Machine @@ -324,8 +339,9 @@ def test_negative_x(self) -> None: with self.assertRaises(SpinnMachineException): machine.validate() - def test_negative_y(self) -> None: - set_config("Machine", "versions", VersionStrings.ANY.text) + @parameterized.expand(ALL_BOARD_TYPES) + def test_negative_y(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) version = MachineDataView.get_machine_version() width, height = version.board_shape # create an empty Machine @@ -341,31 +357,35 @@ def _non_ethernet_chip(self, machine: Machine) -> Chip: return chip raise SpinnMachineException("No none Ethernet Chip") - def test_weird_ethernet1(self) -> None: - set_config("Machine", "versions", VersionStrings.FOUR_PLUS.text) + @parameterized.expand(FOUR_PLUS_BOARD_TYPES) + def test_weird_ethernet1(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) machine = virtual_machine_by_boards(1) self._non_ethernet_chip(machine)._ip_address = "1.2.3.4" with self.assertRaises(SpinnMachineException): machine.validate() - def test_bad_ethernet_chip_x(self) -> None: - set_config("Machine", "versions", VersionStrings.FOUR_PLUS.text) + @parameterized.expand(FOUR_PLUS_BOARD_TYPES) + def test_bad_ethernet_chip_x(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) machine = virtual_machine_by_boards(1) - width, _ = MachineDataView.get_machine_version().board_shape + width, __ = MachineDataView.get_machine_version().board_shape self._non_ethernet_chip(machine)._nearest_ethernet_x = width + 1 with self.assertRaises(SpinnMachineException): machine.validate() - def test_bad_ethernet_chip_no_chip(self) -> None: - set_config("Machine", "versions", VersionStrings.FOUR_PLUS.text) + @parameterized.expand(FOUR_PLUS_BOARD_TYPES) + def test_bad_ethernet_chip_no_chip(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) machine = virtual_machine_by_boards(1) - _, height = MachineDataView.get_machine_version().board_shape + __, height = MachineDataView.get_machine_version().board_shape self._non_ethernet_chip(machine)._nearest_ethernet_x = height + 1 with self.assertRaises(SpinnMachineException): machine.validate() - def test_concentric_xys(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) # Needs a large board + def test_concentric_xys(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) machine = virtual_machine_by_min_size(5, 5) found = list(machine.concentric_xys(2, (2, 2))) expected = [ @@ -375,8 +395,9 @@ def test_concentric_xys(self) -> None: (2, 4), (1, 3), (0, 2), (0, 1), (0, 0), (1, 0)] self.assertListEqual(expected, found) - def test_too_few_cores(self) -> None: - set_config("Machine", "versions", VersionStrings.ANY.text) + @parameterized.expand(ALL_BOARD_TYPES) + def test_too_few_cores(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) machine = virtual_machine_by_boards(1) # Hack to get n_processors return a low number chip = next(machine.chips) diff --git a/unittests/test_using_virtual_machine.py b/unittests/test_using_virtual_machine.py index 5b01a6be..0c953aec 100644 --- a/unittests/test_using_virtual_machine.py +++ b/unittests/test_using_virtual_machine.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from parameterized import parameterized from typing import Tuple import unittest @@ -25,21 +26,20 @@ from spinn_machine.data import MachineDataView from spinn_machine.exceptions import (SpinnMachineException) from spinn_machine.machine_factory import machine_repair -from spinn_machine.version.version_strings import VersionStrings -from spinn_machine.version.version_5 import CHIPS_PER_BOARD +from spinn_machine.version import ( + ALL_BOARD_TYPES, BIG_BOARD_TYPES, FOUR_PLUS_BOARD_TYPES) from .geometry import (to_xyz, shortest_mesh_path_length, shortest_torus_path_length, minimise_xyz) class TestUsingVirtualMachine(unittest.TestCase): - VERSION_5_N_CORES_PER_BOARD = sum(CHIPS_PER_BOARD.values()) - def setUp(self) -> None: unittest_setup() - def test_new_vm_with_max_cores(self) -> None: - set_config("Machine", "versions", VersionStrings.ANY.text) + @parameterized.expand(ALL_BOARD_TYPES) + def test_new_vm_with_max_cores(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) version = MachineDataView.get_machine_version() n_cpus = version.max_cores_per_chip - 5 set_config("Machine", "max_machine_core", str(n_cpus)) @@ -59,8 +59,9 @@ def test_new_vm_with_max_cores(self) -> None: self.assertEqual(version.n_scamp_cores, len(list(chip.scamp_processors_ids))) - def test_iter_chips(self) -> None: - set_config("Machine", "versions", VersionStrings.ANY.text) + @parameterized.expand(ALL_BOARD_TYPES) + def test_iter_chips(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) vm = virtual_machine_by_boards(1) n_chips = MachineDataView.get_machine_version().n_chips_per_board self.assertEqual(n_chips, vm.n_chips) @@ -69,8 +70,9 @@ def test_iter_chips(self) -> None: count += 1 self.assertEqual(n_chips, count) - def test_down_chip(self) -> None: - set_config("Machine", "versions", VersionStrings.FOUR_PLUS.text) + @parameterized.expand(FOUR_PLUS_BOARD_TYPES) + def test_down_chip(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) down_chips = set() down_chips.add((1, 1)) set_config("Machine", "down_chips", "1,1") @@ -89,8 +91,9 @@ def _check_path(self, source: XY, target: XY, path: Tuple[int, int, int], (source[1] + path[1] - path[2]) % height) self.assertEqual(target, new_target, "{}{}".format(source, path)) - def test_nowrap_shortest_path(self) -> None: - set_config("Machine", "versions", VersionStrings.EIGHT_BY_EIGHT.text) + @parameterized.expand(BIG_BOARD_TYPES) # Needs multiple boards + def test_nowrap_shortest_path(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) machine = virtual_machine(16, 28, validate=True) for source in machine.chip_coordinates: for target in machine.chip_coordinates: @@ -103,8 +106,9 @@ def test_nowrap_shortest_path(self) -> None: mac_len, abs(path[0]) + abs(path[1]) + abs(path[2])) self._check_path(source, target, path, 1000000, 1000000) - def test_fullwrap_shortest_path(self) -> None: - set_config("Machine", "versions", VersionStrings.EIGHT_BY_EIGHT.text) + @parameterized.expand(BIG_BOARD_TYPES) # Needs multiple boards + def test_fullwrap_shortest_path(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) width = 12 height = 24 machine = virtual_machine(width, height, validate=True) @@ -120,8 +124,9 @@ def test_fullwrap_shortest_path(self) -> None: "{}{}{}".format(source, target, path)) self._check_path(source, target, path, width, height) - def test_hoizontal_wrap_shortest_path(self) -> None: - set_config("Machine", "versions", VersionStrings.EIGHT_BY_EIGHT.text) + @parameterized.expand(BIG_BOARD_TYPES) # Needs multiple boards + def test_hoizontal_wrap_shortest_path(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) width = 12 height = 16 machine = virtual_machine(width, height, validate=False) @@ -145,8 +150,9 @@ def test_hoizontal_wrap_shortest_path(self) -> None: "{}{}{}".format(source, target, path)) self._check_path(source, target, path, width, height) - def test_vertical_wrap_shortest_path(self) -> None: - set_config("Machine", "versions", VersionStrings.EIGHT_BY_EIGHT.text) + @parameterized.expand(BIG_BOARD_TYPES) # Needs multiple boards + def test_vertical_wrap_shortest_path(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) width = 16 height = 12 machine = virtual_machine(width, height, validate=False) @@ -170,8 +176,9 @@ def test_vertical_wrap_shortest_path(self) -> None: "{}{}{}".format(source, target, path)) self._check_path(source, target, path, width, height) - def test_minimize(self) -> None: - set_config("Machine", "versions", VersionStrings.ANY.text) + @parameterized.expand(ALL_BOARD_TYPES) + def test_minimize(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) machine = virtual_machine_by_boards(1) for x in range(-3, 3): for y in range(-3, 3): @@ -179,8 +186,9 @@ def test_minimize(self) -> None: min2 = machine._minimize_vector(x, y) self.assertEqual(min1, min2) - def test_unreachable_incoming_chips(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) # Needs a large board + def test_unreachable_incoming_chips(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) machine = virtual_machine_by_min_size(6, 6) # Delete links incoming to 3, 3 @@ -192,8 +200,9 @@ def test_unreachable_incoming_chips(self) -> None: unreachable = machine.unreachable_incoming_chips() self.assertListEqual([(3, 3)], unreachable) - def test_unreachable_outgoing_chips(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) # Needs a large board + def test_unreachable_outgoing_chips(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) machine = virtual_machine_by_min_size(6, 6) # Delete links outgoing from 3, 3 @@ -203,8 +212,10 @@ def test_unreachable_outgoing_chips(self) -> None: unreachable = machine.unreachable_outgoing_chips() self.assertListEqual([(3, 3)], unreachable) - def test_unreachable_incoming_local_chips(self) -> None: - set_config("Machine", "versions", VersionStrings.EIGHT_BY_EIGHT.text) + @parameterized.expand(BIG_BOARD_TYPES) # Needs multiple boards + def test_unreachable_incoming_local_chips( + self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) # Assumes boards of exactly size 8,8 down_chips = [(8, 6), (9, 7), (9, 8)] down_str = ":".join([f"{x},{y}" for x, y in down_chips]) @@ -213,8 +224,10 @@ def test_unreachable_incoming_local_chips(self) -> None: unreachable = machine.unreachable_incoming_local_chips() self.assertListEqual([(8, 7)], unreachable) - def test_unreachable_outgoing_local_chips(self) -> None: - set_config("Machine", "versions", VersionStrings.EIGHT_BY_EIGHT.text) + @parameterized.expand(BIG_BOARD_TYPES) # Needs multiple boards + def test_unreachable_outgoing_local_chips( + self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) # Assumes boards of exactly size 8,8 down_chips = [(8, 6), (9, 7), (9, 8)] down_str = ":".join([f"{x},{y}" for x, y in down_chips]) @@ -223,8 +236,9 @@ def test_unreachable_outgoing_local_chips(self) -> None: unreachable = machine.unreachable_outgoing_local_chips() self.assertListEqual([(8, 7)], unreachable) - def test_repair_with_local_orphan(self) -> None: - set_config("Machine", "versions", VersionStrings.EIGHT_BY_EIGHT.text) + @parameterized.expand(BIG_BOARD_TYPES) # Needs multiple boards + def test_repair_with_local_orphan(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) # Assumes boards of exactly size 8,8 down_chips = [(8, 6), (9, 7), (9, 8)] down_str = ":".join([f"{x},{y}" for x, y in down_chips]) @@ -238,8 +252,10 @@ def test_repair_with_local_orphan(self) -> None: self.assertTrue(machine.is_chip_at(8, 7)) self.assertFalse(repaired.is_chip_at(8, 7)) - def test_repair_with_one_way_links_different_boards(self) -> None: - set_config("Machine", "versions", VersionStrings.EIGHT_BY_EIGHT.text) + @parameterized.expand(BIG_BOARD_TYPES) # Needs multiple boards + def test_repair_with_one_way_links_different_boards( + self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) machine = virtual_machine(12, 12) # Assumes boards of exactly size 8,8 # Delete some links between boards @@ -254,8 +270,9 @@ def test_repair_with_one_way_links_different_boards(self) -> None: new_machine = machine_repair(machine) self.assertIsNotNone(new_machine) - def test_oneway_link_no_repair(self) -> None: - set_config("Machine", "versions", VersionStrings.EIGHT_BY_EIGHT.text) + @parameterized.expand(BIG_BOARD_TYPES) # Needs a large board + def test_oneway_link_no_repair(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) machine = virtual_machine(8, 8) # Delete some random links @@ -271,8 +288,9 @@ def test_oneway_link_no_repair(self) -> None: new_machine = machine_repair(machine) self.assertIsNotNone(new_machine) - def test_removed_chip_repair(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) # Needs a large board + def test_removed_chip_repair(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) machine = virtual_machine_by_boards(1) del machine._chips[(3, 3)] @@ -281,8 +299,9 @@ def test_removed_chip_repair(self) -> None: self.assertIsNotNone(new_machine) self.assertFalse(new_machine.is_link_at(2, 2, 1)) - def test_ignores(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) # Needs a large board + def test_ignores(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) set_config("Machine", "down_chips", "2,2:4,4:6,6,ignored_ip") set_config("Machine", "down_cores", "1,1,4:3,3,3: 5,5,-5:7,7,7,ignored_ip:0,0,5-10") diff --git a/unittests/test_virtual_machine_48chips.py b/unittests/test_virtual_machine_48chips.py index 3bf53014..5d4f5179 100644 --- a/unittests/test_virtual_machine_48chips.py +++ b/unittests/test_virtual_machine_48chips.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from parameterized import parameterized import unittest from spinn_utilities.config_holder import set_config @@ -19,7 +20,7 @@ from spinn_machine.config_setup import unittest_setup from spinn_machine.data import MachineDataView from spinn_machine.exceptions import SpinnMachineException -from spinn_machine.version.version_strings import VersionStrings +from spinn_machine.version import BIG_BOARD_TYPES from spinn_machine.virtual_machine import ( virtual_machine_by_boards, virtual_machine_by_chips, virtual_machine_by_cores, virtual_machine_by_min_size) @@ -30,8 +31,9 @@ class TestVirtualMachine48Chips(unittest.TestCase): def setUp(self) -> None: unittest_setup() - def test_illegal_vms(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_illegal_vms(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) with self.assertRaises(SpinnMachineException): virtual_machine(width=-1, height=2) with self.assertRaises(SpinnMachineException): @@ -49,8 +51,9 @@ def test_illegal_vms(self) -> None: virtual_machine(size_x, None, # type: ignore[arg-type] validate=True) - def test_version_hole(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_version_hole(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) set_config("Machine", "down_chips", "3,3") vm = virtual_machine(height=8, width=8, validate=True) self.assertEqual(47, vm.n_chips) @@ -62,8 +65,9 @@ def test_version_hole(self) -> None: self.assertEqual(228, count) self.assertEqual(48, len(list(vm.local_xys))) - def test_version_hole2(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_version_hole2(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) set_config("Machine", "down_chips", "0,3") vm = virtual_machine(height=8, width=8, validate=True) self.assertEqual(47, vm.n_chips) @@ -76,30 +80,34 @@ def test_version_hole2(self) -> None: self.assertEqual(48, len(list(vm.local_xys))) self.assertEqual((0, 4), vm.get_unused_xy()) - def test_12_n_plus4_12_m_4(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_12_n_plus4_12_m_4(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) size_x = 12 * 5 size_y = 12 * 7 vm = virtual_machine(size_x + 4, size_y + 4, validate=True) self.assertEqual(size_x * size_y, vm.n_chips) - def test_12_n_12_m(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_12_n_12_m(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) size_x = 12 * 5 size_y = 12 * 7 vm = virtual_machine(size_x, size_y, validate=True) self.assertEqual(size_x * size_y, vm.n_chips) - def test_chips(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_chips(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) vm = virtual_machine(8, 8) count = 0 for _chip in vm.chips: count += 1 self.assertEqual(count, 48) - def test_ethernet_chips_exist(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_ethernet_chips_exist(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) vm = virtual_machine(width=48, height=24) for eth_chip in vm._ethernet_connected_chips: self.assertTrue(vm.get_chip_at(eth_chip.x, eth_chip.y), @@ -107,14 +115,16 @@ def test_ethernet_chips_exist(self) -> None: "_configured_chips" .format(eth_chip.x, eth_chip.y)) - def test_boot_chip(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_boot_chip(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) vm = virtual_machine(12, 12) # based on Chip equaling its XY self.assertEqual(vm.boot_chip, (0, 0)) - def test_get_chips_on_boards(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_get_chips_on_boards(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) vm = virtual_machine(width=24, height=36) # check each chip appears only once on the entire board count00 = 0 @@ -140,13 +150,15 @@ def test_get_chips_on_boards(self) -> None: # (24,36) is not on this virtual machine self.assertEqual(count2436, 0) - def test_big(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_big(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) virtual_machine( width=240, height=240, validate=True) - def test_48_28(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_48_28(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) machine = virtual_machine(48, 24, validate=True) global_xys = set() for chip in machine.chips: @@ -160,8 +172,9 @@ def test_48_28(self) -> None: self.assertEqual(len(global_xys), 48 * 24) self.assertEqual(48, len(list(machine.local_xys))) - def test_48_24(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_48_24(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) machine = virtual_machine(48, 24, validate=True) global_xys = set() for chip in machine.chips: @@ -175,8 +188,9 @@ def test_48_24(self) -> None: self.assertEqual(len(global_xys), 48 * 24) self.assertEqual(48, len(list(machine.local_xys))) - def test_52_28(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_52_28(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) machine = virtual_machine(48, 24, validate=True) global_xys = set() for chip in machine.chips: @@ -190,8 +204,9 @@ def test_52_28(self) -> None: self.assertEqual(len(global_xys), 48 * 24) self.assertEqual(48, len(list(machine.local_xys))) - def test_52_24(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_52_24(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) machine = virtual_machine(48, 24, validate=True) global_xys = set() for chip in machine.chips: @@ -205,8 +220,9 @@ def test_52_24(self) -> None: self.assertEqual(len(global_xys), 48 * 24) self.assertEqual(48, len(list(machine.local_xys))) - def test_fullwrap_holes(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_fullwrap_holes(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) hole = [(1, 1), (7, 7), (8, 1), (8, 10), (1, 8), (9, 6)] hole_str = ":".join([f"{x},{y}" for x, y in hole]) set_config("Machine", "down_chips", hole_str) @@ -256,8 +272,9 @@ def test_fullwrap_holes(self) -> None: assert xy not in hole self.assertEqual(46, count) - def test_horizontal_wrap_holes(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_horizontal_wrap_holes(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) hole = [(1, 1), (7, 7), (8, 13), (8, 10), (1, 8), (9, 6)] hole_str = ":".join([f"{x},{y}" for x, y in hole]) set_config("Machine", "down_chips", hole_str) @@ -307,8 +324,9 @@ def test_horizontal_wrap_holes(self) -> None: assert xy not in hole self.assertEqual(46, count) - def test_vertical_wrap_holes(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_vertical_wrap_holes(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) hole = [(1, 1), (7, 7), (8, 1), (8, 10), (13, 8), (9, 6)] hole_str = ":".join([f"{x},{y}" for x, y in hole]) set_config("Machine", "down_chips", hole_str) @@ -358,8 +376,9 @@ def test_vertical_wrap_holes(self) -> None: assert xy not in hole self.assertEqual(46, count) - def test_no_wrap_holes(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_no_wrap_holes(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) hole = [(1, 1), (7, 7), (8, 13), (8, 10), (13, 8), (9, 6)] hole_str = ":".join([f"{x},{y}" for x, y in hole]) set_config("Machine", "down_chips", hole_str) @@ -409,8 +428,9 @@ def test_no_wrap_holes(self) -> None: assert xy not in hole self.assertEqual(46, count) - def test_n_cores_full_wrap(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_n_cores_full_wrap(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) version = MachineDataView.get_machine_version() cores_per_board = sum(version.chip_core_map.values()) machine = virtual_machine(12, 12) @@ -421,8 +441,9 @@ def test_n_cores_full_wrap(self) -> None: n_cores = sum(chip.n_processors for chip in machine.chips) self.assertEqual(n_cores, cores_per_board * 3) - def test_n_cores_no_wrap(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_n_cores_no_wrap(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) version = MachineDataView.get_machine_version() cores_per_board = sum(version.chip_core_map.values()) machine = virtual_machine(16, 16) @@ -447,8 +468,9 @@ def test_n_cores_no_wrap(self) -> None: where = machine.where_is_xy(15, 15) self.assertEqual(where, 'No chip 15, 15 found') - def test_n_cores_horizontal_wrap(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_n_cores_horizontal_wrap(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) version = MachineDataView.get_machine_version() cores_per_board = sum(version.chip_core_map.values()) machine = virtual_machine(12, 16) @@ -459,8 +481,9 @@ def test_n_cores_horizontal_wrap(self) -> None: n_cores = sum(chip.n_processors for chip in machine.chips) self.assertEqual(n_cores, cores_per_board * 3) - def test_n_cores_vertical_wrap(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_n_cores_vertical_wrap(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) version = MachineDataView.get_machine_version() cores_per_board = sum(version.chip_core_map.values()) machine = virtual_machine(12, 16) @@ -469,8 +492,9 @@ def test_n_cores_vertical_wrap(self) -> None: n_cores = sum(chip.n_processors for chip in machine.chips) self.assertEqual(n_cores, cores_per_board * 3) - def test_n_cores_8_8(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_n_cores_8_8(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) version = MachineDataView.get_machine_version() cores_per_board = sum(version.chip_core_map.values()) machine = virtual_machine(8, 8) @@ -480,8 +504,9 @@ def test_n_cores_8_8(self) -> None: n_cores = sum(chip.n_processors for chip in machine.chips) self.assertEqual(n_cores, cores_per_board) - def test_8_8_by_cores_1_board(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_8_8_by_cores_1_board(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) version = MachineDataView.get_machine_version() n_cores = sum(version.chip_core_map.values()) n_cores -= version.n_chips_per_board * version.n_scamp_cores @@ -494,8 +519,9 @@ def test_8_8_by_cores_1_board(self) -> None: self.assertEqual(8, machine.height) self.assertEqual(n_cores, machine.total_available_user_cores) - def test_8_8_by_cores_3_boards(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_8_8_by_cores_3_boards(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) version = MachineDataView.get_machine_version() n_cores = sum(version.chip_core_map.values()) n_cores -= version.n_chips_per_board * version.n_scamp_cores @@ -515,8 +541,9 @@ def test_8_8_by_cores_3_boards(self) -> None: self.assertEqual(16, machine.height) self.assertEqual(n_cores*3, machine.total_available_user_cores) - def test_8_8_by_cores_6_boards(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_8_8_by_cores_6_boards(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) version = MachineDataView.get_machine_version() n_cores = sum(version.chip_core_map.values()) n_cores -= version.n_chips_per_board * version.n_scamp_cores @@ -529,8 +556,9 @@ def test_8_8_by_cores_6_boards(self) -> None: self.assertEqual(16, machine.height) self.assertEqual(n_cores * 6, machine.total_available_user_cores) - def test_8_8_by_cores_12_boards(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_8_8_by_cores_12_boards(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) version = MachineDataView.get_machine_version() n_cores = sum(version.chip_core_map.values()) n_cores -= version.n_chips_per_board * version.n_scamp_cores @@ -543,8 +571,9 @@ def test_8_8_by_cores_12_boards(self) -> None: self.assertEqual(28, machine.height) self.assertEqual(n_cores * 12, machine.total_available_user_cores) - def test_8_8_by_cores_18_boards(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_8_8_by_cores_18_boards(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) version = MachineDataView.get_machine_version() n_cores = sum(version.chip_core_map.values()) n_cores -= version.n_chips_per_board * version.n_scamp_cores @@ -557,14 +586,16 @@ def test_8_8_by_cores_18_boards(self) -> None: self.assertEqual(28, machine.height) self.assertEqual(n_cores * 18, machine.total_available_user_cores) - def test_by_min_size(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_by_min_size(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) machine = virtual_machine_by_min_size(15, 21) self.assertGreaterEqual(machine.width, 15) self.assertGreaterEqual(machine.height, 21) - def test_by_min_size_edge_case(self) -> None: - set_config("Machine", "versions", VersionStrings.BIG.text) + @parameterized.expand(BIG_BOARD_TYPES) + def test_by_min_size_edge_case(self, _: str, ver_num: str) -> None: + set_config("Machine", "version", ver_num) version = MachineDataView.get_machine_version() width, height = version.board_shape machine = virtual_machine_by_min_size(width, height + 1) diff --git a/unittests/version/test_version_string.py b/unittests/version/test_version_string.py deleted file mode 100644 index 5b903bae..00000000 --- a/unittests/version/test_version_string.py +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright (c) 2024 The University of Manchester -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -""" -Testing Versions -""" -import unittest -from spinn_machine.config_setup import unittest_setup -from spinn_machine.exceptions import SpinnMachineException -from spinn_machine.version.version_strings import VersionStrings - - -class TestVersionString(unittest.TestCase): - - def setUp(self) -> None: - unittest_setup() - - def test_names(self) -> None: - vs = VersionStrings.from_string("any") - self.assertEqual(vs.text, "Any") - vs = VersionStrings.from_string("FourPlus") - self.assertEqual(vs.text, "Four plus") - with self.assertRaises(SpinnMachineException): - vs = VersionStrings.from_string("Foo") - - -if __name__ == '__main__': - unittest.main()