From d6cb981c7a507ffc479abf58de36063096121d3b Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Sun, 8 Dec 2013 20:23:21 -0700 Subject: [PATCH] migen/test/test_signed: add a (currently failing) signed comparison testcase --- migen/test/test_signed.py | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 migen/test/test_signed.py diff --git a/migen/test/test_signed.py b/migen/test/test_signed.py new file mode 100644 index 00000000..d84691ea --- /dev/null +++ b/migen/test/test_signed.py @@ -0,0 +1,45 @@ +import unittest + +from migen.fhdl.std import * +from migen.test.support import SimCase, SimBench + +class SignedCase(SimCase, unittest.TestCase): + class TestBench(SimBench): + def __init__(self): + self.a = Signal((3, True)) + self.b = Signal((4, True)) + comps = [ + lambda p, q: p > q, + lambda p, q: p >= q, + lambda p, q: p < q, + lambda p, q: p <= q, + lambda p, q: p == q, + lambda p, q: p != q, + ] + self.vals = [] + for asign in 1, -1: + for bsign in 1, -1: + for f in comps: + r = Signal() + r0 = f(asign*self.a, bsign*self.b) + self.comb += r.eq(r0) + self.vals.append((asign, bsign, f, r, r0.op)) + + def test_comparisons(self): + values = range(-4, 4) + agen = iter(values) + bgen = iter(values) + def cb(tb, s): + try: + s.wr(self.tb.a, next(agen)) + s.wr(self.tb.b, next(bgen)) + except StopIteration: + s.interrupt = True + a = s.rd(self.tb.a) + b = s.rd(self.tb.b) + for asign, bsign, f, r, op in self.tb.vals: + r, r0 = s.rd(r), f(asign*a, bsign*b) + self.assertEqual(r, int(r0), + "got {}, want {}*{} {} {}*{} = {}".format( + r, asign, a, op, bsign, b, r0)) + self.run_with(cb) -- 2.30.2