OpenCores
URL https://opencores.org/ocsvn/dmt_tx/dmt_tx/trunk

Subversion Repositories dmt_tx

[/] [dmt_tx/] [trunk/] [myhdl/] [test/] [test_flipSign.py] - Blame information for rev 33

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 dannori
#!/usr/bin/env python
2
 
3
import unittest
4
 
5
from myhdl import *
6
 
7
from rtl.flipSign import flipSign
8
 
9
######################################################################
10
#
11
# Test bench
12
#
13
def bench(tc):
14
  width = 4
15
  max = 2**(width-1)
16
  i_data = Signal(intbv(0, min=-max,max=max))
17
  o_data = Signal(intbv(0, min=-max,max=max))
18
  ovfl = Signal(bool(0))
19
 
20
  dut = flipSign(i_data, o_data, ovfl, width)
21
 
22
  @instance
23
  def check():
24
 
25
    for v in range(-max,max):
26
      i_data.next = v
27
      yield delay(1)
28
      #print 'input: %d output: %d, ovflw: %d'%(i_data, o_data, ovfl)
29
 
30
      if v == -max:
31
        tc.assertEqual(o_data, max-1)
32
        tc.failUnless(ovfl)
33
      else:
34
        tc.assertEqual(o_data, -i_data)
35
 
36
    raise StopSimulation
37
 
38
  return check, dut
39
 
40
 
41
########################################################################
42
#
43
# Test cases
44
#
45
class TestFlipSign(unittest.TestCase):
46
 
47
  def test_flip_sign(self):
48
    '''Verify the sign flip'''
49
    tb = bench(self)
50
    sim = Simulation(tb)
51
    sim.run()
52
 
53
 
54
 
55
########################################################################
56
# main
57
#
58
if __name__ == '__main__':
59
  suite = unittest.TestLoader().loadTestsFromTestCase(TestFlipSign)
60
  unittest.TextTestRunner(verbosity=2).run(suite)

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.