Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1b7020dff36a
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ab5e8fd8da72
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Jan 28, 2016

  1. Copy the full SHA
    982fbb0 View commit details
  2. Copy the full SHA
    ab5e8fd View commit details
Showing with 43 additions and 79 deletions.
  1. +29 −67 artiq/test/hardware_testbench.py
  2. +1 −1 artiq/test/lda.py
  3. +4 −4 artiq/test/novatech409b.py
  4. +9 −7 artiq/test/thorlabs_tcube.py
96 changes: 29 additions & 67 deletions artiq/test/hardware_testbench.py
Original file line number Diff line number Diff line change
@@ -5,14 +5,14 @@
import sys
import unittest
import logging
import asyncio
import threading
import subprocess
import shlex
import time

from artiq.master.databases import DeviceDB, DatasetDB
from artiq.master.worker_db import DeviceManager, DatasetManager
from artiq.coredevice.core import CompileError
from artiq.frontend.artiq_run import DummyScheduler
from artiq.devices.ctlmgr import Controllers


artiq_root = os.getenv("ARTIQ_ROOT")
@@ -21,75 +21,37 @@

@unittest.skipUnless(artiq_root, "no ARTIQ_ROOT")
class ControllerCase(unittest.TestCase):
host_filter = "::1"
timeout = 2

def setUp(self):
if os.name == "nt":
self.loop = asyncio.ProactorEventLoop()
else:
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(self.loop)
self.addCleanup(self.loop.close)

self.loop_thread = threading.Thread(target=self.loop.run_forever)
self.addCleanup(self.loop_thread.join)
self.addCleanup(self.loop.call_soon_threadsafe, self.loop.stop)

self.controllers = Controllers()
self.controllers.host_filter = self.host_filter
self.addCleanup(self._stop_controllers)

self.device_db = DeviceDB(os.path.join(artiq_root, "device_db.pyon"))
self.device_mgr = DeviceManager(self.device_db)
self.addCleanup(self.device_mgr.close_devices)

self.loop_thread.start()

def _stop_controllers(self):
fut = asyncio.run_coroutine_threadsafe(self.controllers.shutdown(),
self.loop)
fut.result()
self.controllers = {}

async def _start(self, *names):
print("FOOO started")
l = asyncio.get_event_loop_policy()
l = l.get_event_loop()
print("FOOO started")
def tearDown(self):
self.device_mgr.close_devices()
for name in list(self.controllers):
self.stop_controller(name)


for name in names:
try:
self.controllers[name] = self.device_db.get(name)
except KeyError:
raise unittest.SkipTest(
"controller `{}` not found".format(name))
await self.controllers.queue.join()
await asyncio.wait([self._wait_for_ping(name)
for name in names])

async def _wait_for_ping(self, name, retries=5):
t = self.timeout
dt = t/retries
while t > 0:
try:
ok = await asyncio.wait_for(
self.controllers.active[name].call("ping"), dt)
if not ok:
raise ValueError("unexcepted ping() response from "
"controller `{}`: `{}`".format(name, ok))
return ok
except asyncio.TimeoutError:
t -= dt
except (ConnectionAbortedError, ConnectionError,
ConnectionRefusedError, ConnectionResetError):
await asyncio.sleep(dt)
t -= dt
raise asyncio.TimeoutError

def start_controllers(self, *names):
fut = asyncio.run_coroutine_threadsafe(self._start(*names), self.loop)
fut.result()
def start_controller(self, name, sleep=1):
try:
entry = self.device_db.get(name)
except KeyError:
raise unittest.SkipTest(
"controller `{}` not found".format(name))
entry["command"] = entry["command"].format(
name=name, bind=entry["host"], port=entry["port"])
proc = subprocess.Popen(shlex.split(entry["command"]))
self.controllers[name] = entry, proc
time.sleep(sleep)

def stop_controller(self, name, default_timeout=1):
entry, proc = self.controllers[name]
t = entry.get("term_timeout", default_timeout)
try:
proc.wait(t)
except subprocess.TimeoutExpired:
proc.kill()
proc.wait(t)
del self.controllers[name]


@unittest.skipUnless(artiq_root, "no ARTIQ_ROOT")
2 changes: 1 addition & 1 deletion artiq/test/lda.py
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ def test_attenuation(self):
class TestLda(ControllerCase, GenericLdaTest):
def setUp(self):
ControllerCase.setUp(self)
self.start_controllers("lda")
self.start_controller("lda")
self.cont = self.device_mgr.get("lda")


8 changes: 4 additions & 4 deletions artiq/test/novatech409b.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest

from artiq.devices.novatech409b.driver import Novatech409B
from artiq.test.hardware_testbench import ControllerCase, with_controllers
from artiq.test.hardware_testbench import ControllerCase


class GenericNovatech409BTest:
@@ -21,10 +21,10 @@ def test_parameters_readback(self):


class TestNovatech409B(GenericNovatech409BTest, ControllerCase):
@with_controllers("novatech409b")
def test_parameters_readback(self):
def setUp(self):
ControllerCase.setUp(self)
self.start_controller("novatech409b")
self.driver = self.device_mgr.get("novatech409b")
GenericNovatech409BTest.test_parameters_readback(self)


class TestNovatech409BSim(GenericNovatech409BTest, unittest.TestCase):
16 changes: 9 additions & 7 deletions artiq/test/thorlabs_tcube.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@

from artiq.devices.thorlabs_tcube.driver import Tdc, Tpz, TdcSim, TpzSim
from artiq.language.units import V
from artiq.test.hardware_testbench import get_from_ddb
from artiq.test.hardware_testbench import ControllerCase


class GenericTdcTest:
@@ -131,21 +131,23 @@ def test_tpz_io_settings(self):
self.assertEqual(test_vector, self.cont.get_tpz_io_settings())


class TestTdc(unittest.TestCase, GenericTdcTest):
class TestTdc(ControllerCase, GenericTdcTest):
def setUp(self):
tdc_serial = get_from_ddb("tdc", "device")
self.cont = Tdc(serial_dev=tdc_serial)
ControllerCase.setUp(self)
self.start_controller("tdc")
self.cont = self.device_mgr.get("tdc")


class TestTdcSim(unittest.TestCase, GenericTdcTest):
def setUp(self):
self.cont = TdcSim()


class TestTpz(unittest.TestCase, GenericTpzTest):
class TestTpz(ControllerCase, GenericTpzTest):
def setUp(self):
tpz_serial = get_from_ddb("tpz", "device")
self.cont = Tpz(serial_dev=tpz_serial)
ControllerCase.setUp(self)
self.start_controller("tpz")
self.cont = self.device_mgr.get("tpz")


class TestTpzSim(unittest.TestCase, GenericTpzTest):