Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Kestrel Collaboration
Kestrel LiteX
migen
Commits
28a5f324
Commit
28a5f324
authored
6 years ago
by
whitequark
Browse files
Options
Download
Email Patches
Plain Diff
genlib/fsm: add basic FSM tests.
parent
9cd4e2cc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
0 deletions
+87
-0
migen/test/test_fsm.py
migen/test/test_fsm.py
+87
-0
No files found.
migen/test/test_fsm.py
0 → 100644
View file @
28a5f324
import
unittest
from
itertools
import
count
from
migen
import
*
from
migen.genlib.fsm
import
FSM
from
migen.test.support
import
SimCase
class
SyncFIFOCase
(
SimCase
,
unittest
.
TestCase
):
class
TestBench
(
Module
):
def
__init__
(
self
):
self
.
ctrl
=
Signal
()
self
.
data
=
Signal
()
self
.
status
=
Signal
(
8
)
self
.
submodules
.
dut
=
FSM
()
self
.
dut
.
act
(
"IDLE"
,
If
(
self
.
ctrl
,
NextState
(
"START"
)
)
)
self
.
dut
.
act
(
"START"
,
If
(
self
.
data
,
NextState
(
"SET-STATUS-LOW"
)
).
Else
(
NextState
(
"SET-STATUS"
)
)
)
self
.
dut
.
act
(
"SET-STATUS"
,
NextValue
(
self
.
status
,
0xaa
),
NextState
(
"IDLE"
)
)
self
.
dut
.
act
(
"SET-STATUS-LOW"
,
NextValue
(
self
.
status
[:
4
],
0xb
),
NextState
(
"IDLE"
)
)
def
assertState
(
self
,
fsm
,
state
):
self
.
assertEqual
(
fsm
.
decoding
[(
yield
fsm
.
state
)],
state
)
def
test_next_state
(
self
):
def
gen
():
yield
from
self
.
assertState
(
self
.
tb
.
dut
,
"IDLE"
)
yield
yield
from
self
.
assertState
(
self
.
tb
.
dut
,
"IDLE"
)
yield
self
.
tb
.
ctrl
.
eq
(
1
)
yield
yield
from
self
.
assertState
(
self
.
tb
.
dut
,
"IDLE"
)
yield
self
.
tb
.
ctrl
.
eq
(
0
)
yield
yield
from
self
.
assertState
(
self
.
tb
.
dut
,
"START"
)
yield
yield
from
self
.
assertState
(
self
.
tb
.
dut
,
"SET-STATUS"
)
yield
self
.
tb
.
ctrl
.
eq
(
1
)
yield
yield
from
self
.
assertState
(
self
.
tb
.
dut
,
"IDLE"
)
yield
self
.
tb
.
ctrl
.
eq
(
0
)
yield
self
.
tb
.
data
.
eq
(
1
)
yield
yield
from
self
.
assertState
(
self
.
tb
.
dut
,
"START"
)
yield
self
.
tb
.
data
.
eq
(
0
)
yield
yield
from
self
.
assertState
(
self
.
tb
.
dut
,
"SET-STATUS-LOW"
)
self
.
run_with
(
gen
())
def
test_next_value
(
self
):
def
gen
():
self
.
assertEqual
((
yield
self
.
tb
.
status
),
0x00
)
yield
self
.
tb
.
ctrl
.
eq
(
1
)
yield
yield
self
.
tb
.
ctrl
.
eq
(
0
)
yield
yield
yield
from
self
.
assertState
(
self
.
tb
.
dut
,
"SET-STATUS"
)
yield
self
.
tb
.
ctrl
.
eq
(
1
)
yield
self
.
assertEqual
((
yield
self
.
tb
.
status
),
0xaa
)
yield
self
.
tb
.
ctrl
.
eq
(
0
)
yield
self
.
tb
.
data
.
eq
(
1
)
yield
yield
self
.
tb
.
data
.
eq
(
0
)
yield
yield
from
self
.
assertState
(
self
.
tb
.
dut
,
"SET-STATUS-LOW"
)
yield
self
.
assertEqual
((
yield
self
.
tb
.
status
),
0xab
)
self
.
run_with
(
gen
())
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment