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

Subversion Repositories dmt_tx

[/] [dmt_tx/] [trunk/] [myhdl/] [test/] [test_flipSign.py] - Rev 33

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

#!/usr/bin/env python
 
import unittest
 
from myhdl import *
 
from rtl.flipSign import flipSign
 
######################################################################
#
# Test bench
#
def bench(tc):
  width = 4
  max = 2**(width-1)
  i_data = Signal(intbv(0, min=-max,max=max))
  o_data = Signal(intbv(0, min=-max,max=max))
  ovfl = Signal(bool(0))
 
  dut = flipSign(i_data, o_data, ovfl, width)
 
  @instance
  def check():
 
    for v in range(-max,max):
      i_data.next = v
      yield delay(1)
      #print 'input: %d output: %d, ovflw: %d'%(i_data, o_data, ovfl)
 
      if v == -max:
        tc.assertEqual(o_data, max-1)
        tc.failUnless(ovfl)
      else:
        tc.assertEqual(o_data, -i_data)
 
    raise StopSimulation
 
  return check, dut
 
 
########################################################################
#
# Test cases
#
class TestFlipSign(unittest.TestCase):
 
  def test_flip_sign(self):
    '''Verify the sign flip'''
    tb = bench(self)
    sim = Simulation(tb)
    sim.run()
 
 
 
########################################################################
# main
#
if __name__ == '__main__':
  suite = unittest.TestLoader().loadTestsFromTestCase(TestFlipSign)
  unittest.TextTestRunner(verbosity=2).run(suite)
 

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

powered by: WebSVN 2.1.0

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