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 30

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 30 dannori
 
50
          # quick test
51
          sizeL = [3, 4, 5, 6, 7, 8, 9, 10, 11]
52 29 dannori
 
53 30 dannori
          # full test
54
          #sizeL = [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
55
 
56
          for size in sizeL:
57 29 dannori
              #print
58
              #print 'Testing const_size %d'%size
59
              #print
60
              const_size_i.next = size
61 28 dannori
 
62 29 dannori
              yield clk.negedge
63
 
64
              for i in range(2**size):
65
                data_i.next = i
66
                wen_i.next = 1
67
                yield clk.negedge
68
                wen_i.next = 0
69
 
70
              yield clk.negedge
71 28 dannori
 
72 29 dannori
          yield clk.negedge
73
          raise StopSimulation
74
 
75 28 dannori
 
76
        @instance
77
        def verify():
78
 
79
          expb2XL = [1, 1, -1, -1]
80
          expb2YL = [1, -1, 1, -1]
81
          expb3XL = [1,  1, -1, -1, -3, 1, -1]
82
          expb3YL = [1, -1,  1, -1,  1, 3, -3]
83
          expb4XL = [1, 1, 3, 3, 1, 1, 3, 3, -3, -3, -1, -1, -3, -3, -1, -1]
84
          expb4YL = [1, 3, 1, 3, -3, -1, -3, -1, 1, 3, 1, 3, -3, -1, -3, -1]
85
          expb5XL = [1, 1, 3, 3,  1,  1,  3,  3, -3, -3, -1, -1, -3, -3, -1, -1,
86
              5, 5, -5, -5, 1,  1, 3,  3, -3, -3, -1, -1,  5,  5, -5, -5]
87
          expb5YL = [1, 3, 1, 3, -3, -1, -3, -1,  1,  3,  1,  3, -3, -1, -3, -1,
88
              1, 3,  1,  3, 5, -5, 5, -5,  5, -5,  5, -5, -3, -1, -3, -1]
89
 
90
 
91 29 dannori
          while True:
92 28 dannori
 
93 29 dannori
              expXL = []
94
              expYL = []
95
 
96
              yield data_valid_o.posedge
97 28 dannori
 
98 29 dannori
              if const_size_i == 2:
99
                expXL = expb2XL
100
                expYL = expb2YL
101
              elif const_size_i == 4:
102
                expXL = expb4XL
103
                expYL = expb4YL
104
              elif const_size_i == 5:
105
                expXL = expb5XL
106
                expYL = expb5YL
107 28 dannori
 
108 29 dannori
              #print "expXL ", expXL
109
              #print "expYL ", expYL
110
              #print "at ", now()
111 28 dannori
 
112
 
113 29 dannori
              for j, expX in enumerate(expXL):
114 28 dannori
 
115 29 dannori
                yield clk.negedge
116
                #print
117
                #print "data_valid: %d x_o: %d y_o: %d at %d"%( data_valid_o,
118
                #                                                x_o, y_o,
119
                #                                                now())
120
                #print "expecting x_o: %d y_o: %d"%(expX, expYL[j])
121
 
122
                if expX != x_o:
123
                  tc.fail("%d != x_o: %d at %d"%(expX, x_o, now()))
124
                if expYL[j] != y_o:
125
                  tc.fail("%d != y_o: %d at %d"%(expYL[j], y_o, now()))
126
 
127
              #raise StopSimulation
128 28 dannori
 
129
        return instances()
130
 
131
 
132
      #####################################
133
      tb = bench(self)
134
      #tb = traceSignals(bench)
135
      sim = Simulation(tb)
136
      sim.run()
137
 
138
 

powered by: WebSVN 2.1.0

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