Skip to content

Commit

Permalink
Merge pull request #1419 from SpiNNakerManchester/avoid_whole_board_s…
Browse files Browse the repository at this point in the history
…kips

Avoid whole board skips
  • Loading branch information
Christian-B authored Dec 1, 2023
2 parents 0ce595c + 9e07841 commit f53f35f
Showing 1 changed file with 47 additions and 29 deletions.
76 changes: 47 additions & 29 deletions test_whole_board/test_whole_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import pyNN.spiNNaker as sim
import spynnaker
from spalloc_client.job import Job
from spalloc_client.states import JobState
import pytest
import tempfile
import os
import traceback
import sys
import time
import logging
from time import sleep
from shutil import rmtree

import pyNN.spiNNaker as sim
from spinnman.spalloc import SpallocClient, SpallocState


class WholeBoardTest(object):
Expand Down Expand Up @@ -57,6 +58,10 @@ class WholeBoardTest(object):
dl = list(ur)
dl.reverse()

def __init__(self):
self.to_allocate = None
self.targets = None

def find_a_placement(self):
for count in range(17, 0, -1):
for (x, y), processors in self.to_allocate.items():
Expand Down Expand Up @@ -187,40 +192,53 @@ def do_run(self):
sim.end()


boards = [(x, y, b) for x in range(20) for y in range(20) for b in range(3)]
BOARDS = [(x, y, b) for x in range(20) for y in range(20) for b in range(3)]
SPALLOC_URL = "https://spinnaker.cs.man.ac.uk/spalloc"
SPALLOC_USERNAME = "jenkins"
SPALLOC_PASSWORD = os.getenv("SPALLOC_PASSWORD")
SPALLOC_MACHINE = "SpiNNaker1M"


@pytest.mark.parametrize("x,y,b", boards)
@pytest.mark.parametrize("x,y,b", BOARDS)
def test_run(x, y, b):
test_dir = os.path.dirname(__file__)
job = Job(x, y, b, hostname="spinnaker.cs.man.ac.uk",
owner="Jenkins Machine Test")
# Sleep before checking for queued in case of multiple jobs running
time.sleep(2.0)
if job.state == JobState.queued:
job.destroy("Queued")
pytest.skip(f"Board {x}, {y}, {b} is in use")
elif job.state == JobState.destroyed:
pytest.skip(f"Board {x}, {y}, {b} could not be allocated")
client = SpallocClient(SPALLOC_URL, SPALLOC_USERNAME, SPALLOC_PASSWORD)
job = client.create_job_board(
triad=(x, y, b), machine_name=SPALLOC_MACHINE)
with job:
with tempfile.TemporaryDirectory(
prefix=f"{x}_{y}_{b}", dir=test_dir) as tmpdir:
os.chdir(tmpdir)
with open("spynnaker.cfg", "w", encoding="utf-8") as f:
f.write("[Machine]\n")
f.write("spalloc_server = None\n")
f.write(f"machine_name = {job.hostname}\n")
f.write("version = 5\n")
test = WholeBoardTest()
test.do_run()
job.launch_keepalive_task()
job.wait_until_ready(n_retries=2)
state = job.get_state()
# If queued or destroyed skip test
if state == SpallocState.QUEUED:
job.destroy("Queued")
pytest.skip(f"Some boards starting at {x}, {y}, {b} is in use")
elif state == SpallocState.DESTROYED:
pytest.skip(f"Boards {x}, {y}, {b} could not be allocated")
# Actually wait for ready now (as might be powering on)
job.wait_until_ready()
tmpdir = tempfile.mkdtemp(prefix=f"{x}_{y}_{b}", dir=test_dir)
os.chdir(tmpdir)
with open("spynnaker.cfg", "w", encoding="utf-8") as f:
f.write("[Machine]\n")
f.write("spalloc_server = None\n")
f.write(f"machine_name = {job.get_root_host()}\n")
f.write("version = 5\n")
test = WholeBoardTest()
test.do_run()
# If no errors we will get here and we can remove the tree;
# then only error folders will be left
rmtree(tmpdir)


if __name__ == "__main__":
for x, y, b in boards:
logging.basicConfig(level=logging.DEBUG)
main_boards = [(0, 0, 0)]
for b_x, b_y, b_b in main_boards:
print("", file=sys.stderr,)
print(f"*************** Testing {x}, {y}, {b} *******************",
print(f"************** Testing {b_x}, {b_y}, {b_b} ******************",
file=sys.stderr)
try:
test_run(x, y, b)
test_run(b_x, b_y, b_b)
except Exception:
traceback.print_exc()

0 comments on commit f53f35f

Please sign in to comment.