2013-11-29 21:52:42 -05:00
|
|
|
import unittest
|
|
|
|
from random import randrange
|
|
|
|
|
2015-09-12 07:34:07 -04:00
|
|
|
from migen import *
|
2013-11-29 21:52:42 -05:00
|
|
|
from migen.genlib.sort import *
|
|
|
|
|
2015-09-12 04:28:21 -04:00
|
|
|
from migen.test.support import SimCase
|
2013-11-29 21:52:42 -05:00
|
|
|
|
2015-04-13 14:45:35 -04:00
|
|
|
|
2013-11-29 21:52:42 -05:00
|
|
|
class BitonicCase(SimCase, unittest.TestCase):
|
2015-09-12 04:28:21 -04:00
|
|
|
class TestBench(Module):
|
2015-04-13 14:07:07 -04:00
|
|
|
def __init__(self):
|
|
|
|
self.submodules.dut = BitonicSort(8, 4, ascending=True)
|
2013-11-29 21:52:42 -05:00
|
|
|
|
2015-04-13 14:07:07 -04:00
|
|
|
def test_sizes(self):
|
|
|
|
self.assertEqual(len(self.tb.dut.i), 8)
|
|
|
|
self.assertEqual(len(self.tb.dut.o), 8)
|
|
|
|
for i in range(8):
|
|
|
|
self.assertEqual(flen(self.tb.dut.i[i]), 4)
|
|
|
|
self.assertEqual(flen(self.tb.dut.o[i]), 4)
|
2013-11-29 21:52:42 -05:00
|
|
|
|
2015-04-13 14:07:07 -04:00
|
|
|
def test_sort(self):
|
2015-09-12 04:28:21 -04:00
|
|
|
def gen():
|
|
|
|
for repeat in range(20):
|
|
|
|
for i in self.tb.dut.i:
|
|
|
|
yield i, randrange(1<<flen(i))
|
|
|
|
yield
|
|
|
|
self.assertEqual(sorted((yield self.tb.dut.i)),
|
|
|
|
(yield self.tb.dut.o))
|
|
|
|
self.run_with(gen())
|