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

Subversion Repositories dmt_tx

[/] [dmt_tx/] [trunk/] [myhdl/] [test/] [test_const_encoder.py] - Blame information for rev 28

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

Line No. Rev Author Line
1 28 dannori
#!/usr/bin/env python
2
 
3
import unittest
4
 
5
import os
6
from myhdl import *
7
 
8
import random
9
 
10
from rtl.const_encoder import const_encoder
11
 
12
 
13
########################################################################
14
#
15
# Test cases
16
#
17
class TestConstEncoder(unittest.TestCase):
18
 
19
    def test_const_encoder(self):
20
 
21
      def bench(tc):
22
 
23
        clk, reset, \
24
            wen_i, data_valid_o \
25
            = [Signal(bool(0)) for i in range(4)]
26
 
27
        const_size_i = Signal(intbv(0)[4:])
28
        data_i = Signal(intbv(0)[15:])
29
        x_o, y_o = [Signal(intbv(0, min=-256, max=256)) for i in range(2)]
30
 
31
        const_encoder_inst = const_encoder( clk, reset,
32
                                            wen_i, const_size_i,
33
                                            data_i,
34
                                            data_valid_o, x_o, y_o)
35
 
36
 
37
        @always(delay(10))
38
        def clkgen():
39
          clk.next = not clk
40
 
41
        @instance
42
        def stimulus():
43
 
44
          yield clk.negedge
45
          reset.next = 1
46
          yield clk.negedge
47
          reset.next = 0
48
 
49
          size = 5
50
          const_size_i.next = size
51
 
52
          for i in range(2**size):
53
            data_i.next = i
54
            wen_i.next = 1
55
            yield clk.negedge
56
            wen_i.next = 0
57
 
58
 
59
        @instance
60
        def verify():
61
 
62
          expb2XL = [1, 1, -1, -1]
63
          expb2YL = [1, -1, 1, -1]
64
          expb3XL = [1,  1, -1, -1, -3, 1, -1]
65
          expb3YL = [1, -1,  1, -1,  1, 3, -3]
66
          expb4XL = [1, 1, 3, 3, 1, 1, 3, 3, -3, -3, -1, -1, -3, -3, -1, -1]
67
          expb4YL = [1, 3, 1, 3, -3, -1, -3, -1, 1, 3, 1, 3, -3, -1, -3, -1]
68
          expb5XL = [1, 1, 3, 3,  1,  1,  3,  3, -3, -3, -1, -1, -3, -3, -1, -1,
69
              5, 5, -5, -5, 1,  1, 3,  3, -3, -3, -1, -1,  5,  5, -5, -5]
70
          expb5YL = [1, 3, 1, 3, -3, -1, -3, -1,  1,  3,  1,  3, -3, -1, -3, -1,
71
              1, 3,  1,  3, 5, -5, 5, -5,  5, -5,  5, -5, -3, -1, -3, -1]
72
 
73
 
74
          expXL = []
75
          expYL = []
76
 
77
          yield data_valid_o.posedge
78
 
79
          if const_size_i == 2:
80
            expXL = expb2XL
81
            expYL = expb2YL
82
          elif const_size_i == 4:
83
            expXL = expb4XL
84
            expYL = expb4YL
85
          elif const_size_i == 5:
86
            expXL = expb5XL
87
            expYL = expb5YL
88
 
89
          #print "expXL ", expXL
90
          #print "expYL ", expYL
91
          #print "at ", now()
92
 
93
 
94
          for j, expX in enumerate(expXL):
95
 
96
            yield clk.negedge
97
            #print
98
            #print "data_valid: %d x_o: %d y_o: %d at %d"%( data_valid_o,
99
            #                                                x_o, y_o,
100
            #                                                now())
101
            #print "expecting x_o: %d y_o: %d"%(expX, expYL[j])
102
 
103
            if expX != x_o:
104
              tc.fail("%d != x_o: %d at %d"%(expX, x_o, now()))
105
            if expYL[j] != y_o:
106
              tc.fail("%d != y_o: %d at %d"%(expYL[j], y_o, now()))
107
 
108
          raise StopSimulation
109
 
110
        return instances()
111
 
112
 
113
      #####################################
114
      tb = bench(self)
115
      #tb = traceSignals(bench)
116
      sim = Simulation(tb)
117
      sim.run()
118
 
119
 

powered by: WebSVN 2.1.0

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