Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
litex
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jonathan Currier
litex
Commits
8fdd5220
Commit
8fdd5220
authored
Jun 10, 2019
by
Florent Kermarrec
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test/test_prbs: add PRBSGenerator/Checker tests
parent
243d7c76
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
103 additions
and
0 deletions
+103
-0
test/test_prbs.py
test/test_prbs.py
+103
-0
No files found.
test/test_prbs.py
0 → 100644
View file @
8fdd5220
import
unittest
from
migen
import
*
from
litex.soc.cores.prbs
import
*
class
PRBSModel
:
def
__init__
(
self
,
n_state
=
23
,
taps
=
[
17
,
22
]):
self
.
n_state
=
n_state
self
.
taps
=
taps
self
.
state
=
1
def
getbit
(
self
):
feedback
=
0
for
tap
in
self
.
taps
:
feedback
=
feedback
^
(
self
.
state
>>
tap
)
&
0x1
self
.
state
=
(
self
.
state
<<
1
)
&
(
2
**
self
.
n_state
-
1
)
|
feedback
return
feedback
def
getbits
(
self
,
n
):
v
=
0
for
i
in
range
(
n
):
v
<<=
1
v
|=
self
.
getbit
()
return
v
class
PRBS7Model
(
PRBSModel
):
def
__init__
(
self
):
PRBSModel
.
__init__
(
self
,
n_state
=
7
,
taps
=
[
5
,
6
])
class
PRBS15Model
(
PRBSModel
):
def
__init__
(
self
):
PRBSModel
.
__init__
(
self
,
n_state
=
15
,
taps
=
[
13
,
14
])
class
PRBS31Model
(
PRBSModel
):
def
__init__
(
self
):
PRBSModel
.
__init__
(
self
,
n_state
=
31
,
taps
=
[
27
,
30
])
class
TestPRBS
(
unittest
.
TestCase
):
def
test_prbs_generator
(
self
):
duts
=
{
"prbs7"
:
PRBS7Generator
(
8
),
"prbs15"
:
PRBS15Generator
(
16
),
"prbs31"
:
PRBS31Generator
(
32
),
}
models
=
{
"prbs7"
:
PRBS7Model
(),
"prbs15"
:
PRBS15Model
(),
"prbs31"
:
PRBS31Model
(),
}
errors
=
0
for
test
in
[
"prbs7"
,
"prbs15"
,
"prbs31"
]:
dut
=
duts
[
test
]
dut
.
_errors
=
0
model
=
models
[
test
]
def
checker
(
dut
,
cycles
):
yield
# Let the generator run and check values against model.
for
i
in
range
(
cycles
):
if
(
yield
dut
.
o
)
!=
model
.
getbits
(
len
(
dut
.
o
)):
dut
.
_errors
+=
1
yield
run_simulation
(
dut
,
checker
(
dut
,
1024
))
self
.
assertEqual
(
dut
.
_errors
,
0
)
def
test_prbs_checker
(
self
):
duts
=
{
"prbs7"
:
PRBS7Checker
(
8
),
"prbs15"
:
PRBS15Checker
(
16
),
"prbs31"
:
PRBS31Checker
(
32
),
}
models
=
{
"prbs7"
:
PRBS7Model
(),
"prbs15"
:
PRBS15Model
(),
"prbs31"
:
PRBS31Model
(),
}
errors
=
0
for
test
in
[
"prbs7"
,
"prbs15"
,
"prbs31"
]:
dut
=
duts
[
test
]
dut
.
_errors
=
0
model
=
models
[
test
]
@
passive
def
generator
(
dut
):
# Inject PRBS values from model.
while
True
:
yield
dut
.
i
.
eq
(
model
.
getbits
(
len
(
dut
.
i
)))
yield
def
checker
(
dut
,
cycles
):
# Wait PRBS synchronization.
for
i
in
range
(
8
):
yield
# Check that no errors are reported.
for
i
in
range
(
cycles
):
if
(
yield
dut
.
errors
)
!=
0
:
dut
.
_errors
+=
1
yield
run_simulation
(
dut
,
[
generator
(
dut
),
checker
(
dut
,
1024
)])
self
.
assertEqual
(
dut
.
_errors
,
0
)
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