Merge branch 'master' of github.com:m-labs/artiq

This commit is contained in:
Sebastien Bourdeauducq 2015-06-04 10:35:52 +08:00
commit 448ba042b5
6 changed files with 45 additions and 19 deletions

View File

@ -73,8 +73,10 @@ class RPCCase(unittest.TestCase):
remote.close_rpc() remote.close_rpc()
def _loop_asyncio_echo(self): def _loop_asyncio_echo(self):
loop = asyncio.get_event_loop() loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(self._asyncio_echo()) loop.run_until_complete(self._asyncio_echo())
loop.close()
def test_asyncio_echo(self): def test_asyncio_echo(self):
self._run_server_and_test(self._loop_asyncio_echo) self._run_server_and_test(self._loop_asyncio_echo)
@ -96,7 +98,8 @@ class Echo:
def run_server(): def run_server():
loop = asyncio.get_event_loop() loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
try: try:
echo = Echo() echo = Echo()
server = pc_rpc.Server({"test": echo}) server = pc_rpc.Server({"test": echo})

View File

@ -55,7 +55,12 @@ _handlers = {
class SchedulerCase(unittest.TestCase): class SchedulerCase(unittest.TestCase):
def setUp(self):
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(self.loop)
def test_steps(self): def test_steps(self):
loop = self.loop
scheduler = Scheduler(0, _handlers) scheduler = Scheduler(0, _handlers)
expid = _get_expid("EmptyExperiment") expid = _get_expid("EmptyExperiment")
@ -70,7 +75,6 @@ class SchedulerCase(unittest.TestCase):
done.set() done.set()
scheduler.notifier.publish = notify scheduler.notifier.publish = notify
loop = asyncio.get_event_loop()
scheduler.start() scheduler.start()
# Verify that a timed experiment far in the future does not # Verify that a timed experiment far in the future does not
@ -91,6 +95,7 @@ class SchedulerCase(unittest.TestCase):
loop.run_until_complete(scheduler.stop()) loop.run_until_complete(scheduler.stop())
def test_pause(self): def test_pause(self):
loop = self.loop
scheduler = Scheduler(0, _handlers) scheduler = Scheduler(0, _handlers)
expid_bg = _get_expid("BackgroundExperiment") expid_bg = _get_expid("BackgroundExperiment")
expid = _get_expid("EmptyExperiment") expid = _get_expid("EmptyExperiment")
@ -113,7 +118,6 @@ class SchedulerCase(unittest.TestCase):
done.set() done.set()
scheduler.notifier.publish = notify scheduler.notifier.publish = notify
loop = asyncio.get_event_loop()
scheduler.start() scheduler.start()
scheduler.submit("main", expid_bg, -99, None, False) scheduler.submit("main", expid_bg, -99, None, False)
loop.run_until_complete(background_running.wait()) loop.run_until_complete(background_running.wait())
@ -122,6 +126,7 @@ class SchedulerCase(unittest.TestCase):
loop.run_until_complete(scheduler.stop()) loop.run_until_complete(scheduler.stop())
def test_flush(self): def test_flush(self):
loop = self.loop
scheduler = Scheduler(0, _handlers) scheduler = Scheduler(0, _handlers)
expid = _get_expid("EmptyExperiment") expid = _get_expid("EmptyExperiment")
@ -147,10 +152,12 @@ class SchedulerCase(unittest.TestCase):
done.set() done.set()
scheduler.notifier.publish = notify scheduler.notifier.publish = notify
loop = asyncio.get_event_loop()
scheduler.start() scheduler.start()
scheduler.submit("main", expid, 0, None, False) scheduler.submit("main", expid, 0, None, False)
loop.run_until_complete(first_preparing.wait()) loop.run_until_complete(first_preparing.wait())
scheduler.submit("main", expid, 1, None, True) scheduler.submit("main", expid, 1, None, True)
loop.run_until_complete(done.wait()) loop.run_until_complete(done.wait())
loop.run_until_complete(scheduler.stop()) loop.run_until_complete(scheduler.stop())
def tearDown(self):
self.loop.close()

View File

@ -1,5 +1,6 @@
import unittest import unittest
import asyncio import asyncio
import numpy as np
from artiq.protocols import sync_struct from artiq.protocols import sync_struct
@ -9,8 +10,14 @@ test_port = 7777
@asyncio.coroutine @asyncio.coroutine
def write_test_data(test_dict): def write_test_data(test_dict):
test_values = [5, 2.1, None, True, False,
{"a": 5, 2: np.linspace(0, 10, 1)},
(4, 5), (10,), "ab\nx\"'"]
for i in range(10): for i in range(10):
test_dict[str(i)] = i test_dict[str(i)] = i
for key, value in enumerate(test_values):
test_dict[key] = value
test_dict[1.5] = 1.5
test_dict["Finished"] = True test_dict["Finished"] = True
@ -29,15 +36,18 @@ class SyncStructCase(unittest.TestCase):
self.test_dict = init self.test_dict = init
return init return init
@asyncio.coroutine def notify(self, mod):
def do_recv(self): if (mod["action"] == "init" and "Finished" in mod["struct"])\
while not hasattr(self, "test_dict")\ or (mod["action"] == "setitem" and mod["key"] == "Finished"):
or "Finished" not in self.test_dict.keys(): self.receiving_done.set()
yield from asyncio.sleep(0.5)
def setUp(self):
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(self.loop)
def test_recv(self): def test_recv(self):
self.loop = loop = asyncio.new_event_loop() loop = self.loop
asyncio.set_event_loop(loop) self.receiving_done = asyncio.Event()
publisher = asyncio.Future() publisher = asyncio.Future()
test_dict = asyncio.Future() test_dict = asyncio.Future()
asyncio.async(start_server(publisher, test_dict)) asyncio.async(start_server(publisher, test_dict))
@ -50,13 +60,14 @@ class SyncStructCase(unittest.TestCase):
loop.run_until_complete(write_test_data(test_vector)) loop.run_until_complete(write_test_data(test_vector))
asyncio.async(write_test_data(test_dict)) asyncio.async(write_test_data(test_dict))
self.subscriber = sync_struct.Subscriber("test", self.init_test_dict) self.subscriber = sync_struct.Subscriber("test", self.init_test_dict,
self.notify)
loop.run_until_complete(self.subscriber.connect(test_address, loop.run_until_complete(self.subscriber.connect(test_address,
test_port)) test_port))
loop.run_until_complete(self.do_recv()) loop.run_until_complete(self.receiving_done.wait())
self.assertEqual(self.test_dict, test_vector) self.assertEqual(self.test_dict, test_vector)
def tearDown(self):
self.loop.run_until_complete(self.subscriber.close()) self.loop.run_until_complete(self.subscriber.close())
self.loop.run_until_complete(self.publisher.stop()) self.loop.run_until_complete(self.publisher.stop())
def tearDown(self):
self.loop.close() self.loop.close()

View File

@ -40,6 +40,8 @@ def _call_worker(worker, expid):
def _run_experiment(experiment): def _run_experiment(experiment):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
expid = { expid = {
"file": sys.modules[__name__].__file__, "file": sys.modules[__name__].__file__,
"experiment": experiment, "experiment": experiment,
@ -50,8 +52,8 @@ def _run_experiment(experiment):
} }
worker = Worker(handlers) worker = Worker(handlers)
loop = asyncio.get_event_loop()
loop.run_until_complete(_call_worker(worker, expid)) loop.run_until_complete(_call_worker(worker, expid))
loop.close()
class WatchdogCase(unittest.TestCase): class WatchdogCase(unittest.TestCase):

View File

@ -27,13 +27,13 @@ build:
requirements: requirements:
build: build:
- python - python >=3.4.3
- setuptools - setuptools
- numpy - numpy
- migen - migen
- pyelftools - pyelftools
run: run:
- python - python >=3.4.3
- llvmlite-or1k - llvmlite-or1k
- scipy - scipy
- numpy - numpy

View File

@ -1,7 +1,10 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from setuptools import setup, find_packages from setuptools import setup, find_packages
import sys
if sys.version_info[:3] < (3, 4, 3):
raise Exception("You need at least Python 3.4.3 to run ARTIQ")
requirements = [ requirements = [
"sphinx", "sphinx-argparse", "pyserial", "numpy", "scipy", "sphinx", "sphinx-argparse", "pyserial", "numpy", "scipy",