test/full_stack/pulses: compare results on host and device

This commit is contained in:
Sebastien Bourdeauducq 2014-10-08 18:02:07 +08:00
parent 2920ac85d2
commit 46165f3b50
1 changed files with 23 additions and 10 deletions

View File

@ -1,4 +1,5 @@
import unittest import unittest
from operator import itemgetter
from artiq import * from artiq import *
from artiq.devices import corecom_serial, core, runtime_exceptions, rtio_core from artiq.devices import corecom_serial, core, runtime_exceptions, rtio_core
@ -36,22 +37,29 @@ class _Primes(AutoContext):
class _PulseLogger(AutoContext): class _PulseLogger(AutoContext):
parameters = "name" parameters = "output_list name"
def print_on(self, t, f): def _append(self, t, l, f):
print("{} ON:{:4} @{}".format(self.name, f, t)) if not hasattr(self, "first_timestamp"):
self.first_timestamp = t
self.output_list.append((self.name, t-self.first_timestamp, l, f))
def print_off(self, t): def on(self, t, f):
print("{} OFF @{}".format(self.name, t)) self._append(t, True, f)
def off(self, t):
self._append(t, False, 0)
@kernel @kernel
def pulse(self, f, duration): def pulse(self, f, duration):
self.print_on(int(now()), f) self.on(int(now().amount*1000000000), f)
delay(duration) delay(duration)
self.print_off(int(now())) self.off(int(now().amount*1000000000))
class _Pulses(AutoContext): class _Pulses(AutoContext):
parameters = "output_list"
def build(self): def build(self):
for name in "a", "b", "c", "d": for name in "a", "b", "c", "d":
pl = _PulseLogger(self, name=name) pl = _PulseLogger(self, name=name)
@ -123,9 +131,14 @@ class SimCompareCase(unittest.TestCase):
self.assertEqual(l_device, l_host) self.assertEqual(l_device, l_host)
def test_pulses(self): def test_pulses(self):
# TODO: compare results on host and device l_device, l_host = [], []
# (this requires better unit management in the compiler) _run_on_device(_Pulses, output_list=l_device)
_run_on_device(_Pulses) _run_on_host(_Pulses, output_list=l_host)
l_host = sorted(l_host, key=itemgetter(1))
for channel in "a", "b", "c", "d":
c_device = [x for x in l_device if x[0] == channel]
c_host = [x for x in l_host if x[0] == channel]
self.assertEqual(c_device, c_host)
def test_exceptions(self): def test_exceptions(self):
t_device, t_host = [], [] t_device, t_host = [], []