2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-25 03:08:27 +08:00

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()
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.close()
def test_asyncio_echo(self):
self._run_server_and_test(self._loop_asyncio_echo)
@ -96,7 +98,8 @@ class Echo:
def run_server():
loop = asyncio.get_event_loop()
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
try:
echo = Echo()
server = pc_rpc.Server({"test": echo})

View File

@ -55,7 +55,12 @@ _handlers = {
class SchedulerCase(unittest.TestCase):
def setUp(self):
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(self.loop)
def test_steps(self):
loop = self.loop
scheduler = Scheduler(0, _handlers)
expid = _get_expid("EmptyExperiment")
@ -70,7 +75,6 @@ class SchedulerCase(unittest.TestCase):
done.set()
scheduler.notifier.publish = notify
loop = asyncio.get_event_loop()
scheduler.start()
# 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())
def test_pause(self):
loop = self.loop
scheduler = Scheduler(0, _handlers)
expid_bg = _get_expid("BackgroundExperiment")
expid = _get_expid("EmptyExperiment")
@ -113,7 +118,6 @@ class SchedulerCase(unittest.TestCase):
done.set()
scheduler.notifier.publish = notify
loop = asyncio.get_event_loop()
scheduler.start()
scheduler.submit("main", expid_bg, -99, None, False)
loop.run_until_complete(background_running.wait())
@ -122,6 +126,7 @@ class SchedulerCase(unittest.TestCase):
loop.run_until_complete(scheduler.stop())
def test_flush(self):
loop = self.loop
scheduler = Scheduler(0, _handlers)
expid = _get_expid("EmptyExperiment")
@ -147,10 +152,12 @@ class SchedulerCase(unittest.TestCase):
done.set()
scheduler.notifier.publish = notify
loop = asyncio.get_event_loop()
scheduler.start()
scheduler.submit("main", expid, 0, None, False)
loop.run_until_complete(first_preparing.wait())
scheduler.submit("main", expid, 1, None, True)
loop.run_until_complete(done.wait())
loop.run_until_complete(scheduler.stop())
def tearDown(self):
self.loop.close()

View File

@ -1,5 +1,6 @@
import unittest
import asyncio
import numpy as np
from artiq.protocols import sync_struct
@ -9,8 +10,14 @@ test_port = 7777
@asyncio.coroutine
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):
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
@ -29,15 +36,18 @@ class SyncStructCase(unittest.TestCase):
self.test_dict = init
return init
@asyncio.coroutine
def do_recv(self):
while not hasattr(self, "test_dict")\
or "Finished" not in self.test_dict.keys():
yield from asyncio.sleep(0.5)
def notify(self, mod):
if (mod["action"] == "init" and "Finished" in mod["struct"])\
or (mod["action"] == "setitem" and mod["key"] == "Finished"):
self.receiving_done.set()
def setUp(self):
self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(self.loop)
def test_recv(self):
self.loop = loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop = self.loop
self.receiving_done = asyncio.Event()
publisher = asyncio.Future()
test_dict = asyncio.Future()
asyncio.async(start_server(publisher, test_dict))
@ -50,13 +60,14 @@ class SyncStructCase(unittest.TestCase):
loop.run_until_complete(write_test_data(test_vector))
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,
test_port))
loop.run_until_complete(self.do_recv())
loop.run_until_complete(self.receiving_done.wait())
self.assertEqual(self.test_dict, test_vector)
def tearDown(self):
self.loop.run_until_complete(self.subscriber.close())
self.loop.run_until_complete(self.publisher.stop())
def tearDown(self):
self.loop.close()

View File

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

View File

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

View File

@ -1,7 +1,10 @@
#!/usr/bin/env python3
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 = [
"sphinx", "sphinx-argparse", "pyserial", "numpy", "scipy",