2 from gram
.test
.utils
.formal
import FHDLTestCase
5 from nmigen
.hdl
.ast
import Past
6 from nmigen
.asserts
import Assert
, Assume
8 from gram
.compat
import *
10 class DelayedEnterTestCase(unittest
.TestCase
):
11 def test_sequence(self
):
12 def sequence(expected_delay
):
19 with m
.State("Before-Delayed-Enter"):
20 m
.d
.comb
+= before
.eq(1)
21 m
.next
= "Delayed-Enter"
23 delayed_enter(m
, "Delayed-Enter", "End-Delayed-Enter", expected_delay
)
25 with m
.State("End-Delayed-Enter"):
33 while not (yield end
):
37 self
.assertEqual(delay
, expected_delay
)
40 with sim
.write_vcd("test_compat.vcd"):
42 sim
.add_sync_process(process
)
45 with self
.assertRaises(AssertionError):
53 class TimelineTestCase(unittest
.TestCase
):
54 def test_sequence(self
):
66 m
.submodules
.timeline
= timeline
69 # Test default value for unset signals
70 self
.assertFalse((yield sigA
))
71 self
.assertFalse((yield sigB
))
73 # Ensure that the sequence isn't triggered without the trigger signal
76 self
.assertFalse((yield sigA
))
77 self
.assertFalse((yield sigB
))
79 yield timeline
.trigger
.eq(1)
81 yield timeline
.trigger
.eq(0)
87 self
.assertTrue((yield sigA
))
88 self
.assertFalse((yield sigB
))
90 self
.assertTrue((yield sigA
))
91 self
.assertFalse((yield sigB
))
93 self
.assertFalse((yield sigA
))
94 self
.assertFalse((yield sigB
))
96 self
.assertFalse((yield sigA
))
97 self
.assertTrue((yield sigB
))
99 self
.assertFalse((yield sigA
))
100 self
.assertFalse((yield sigB
))
102 # Ensure no changes happen once the sequence is done
105 self
.assertFalse((yield sigA
))
106 self
.assertFalse((yield sigB
))
109 with sim
.write_vcd("test_compat.vcd"):
111 sim
.add_sync_process(process
)
114 class RoundRobinOutputMatchSpec(Elaboratable
):
115 def __init__(self
, dut
):
118 def elaborate(self
, platform
):
121 m
.d
.comb
+= Assume(Rose(self
.dut
.stb
).implies(self
.dut
.request
== Past(self
.dut
.request
)))
123 m
.d
.sync
+= Assert(((Past(self
.dut
.request
) != 0) & Past(self
.dut
.stb
)).implies(Past(self
.dut
.request
) & (1 << self
.dut
.grant
)))
127 class RoundRobinTestCase(FHDLTestCase
):
128 def test_sequence(self
):
130 m
.submodules
.rb
= roundrobin
= RoundRobin(8)
133 yield roundrobin
.request
.eq(0b10001000)
134 yield roundrobin
.stb
.eq(1)
138 self
.assertEqual((yield roundrobin
.grant
), 3)
141 self
.assertEqual((yield roundrobin
.grant
), 7)
144 self
.assertEqual((yield roundrobin
.grant
), 3)
145 yield roundrobin
.request
.eq(0b00000001)
149 self
.assertEqual((yield roundrobin
.grant
), 0)
152 with sim
.write_vcd("test_compat.vcd"):
154 sim
.add_sync_process(process
)
157 # def test_output_match(self):
158 # roundrobin = RoundRobin(32)
159 # spec = RoundRobinOutputMatchSpec(roundrobin)
160 # self.assertFormal(spec, mode="bmc", depth=10)