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 29

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

powered by: WebSVN 2.1.0

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