1
1
import random
2
+ import string
2
3
from decimal import Decimal
3
4
4
5
import siliconcompiler
@@ -30,6 +31,12 @@ def bursty_en_gen(burst_len=20):
30
31
yield en_state
31
32
32
33
34
+ def random_decimal (max : int , min : int , decimal_places = 2 ) -> Decimal :
35
+ prefix = str (random .randint (min , max ))
36
+ suffix = '' .join (random .choice (string .digits ) for _ in range (decimal_places ))
37
+ return Decimal (prefix + "." + suffix )
38
+
39
+
33
40
@cocotb .test ()
34
41
async def test_almost_full (dut ):
35
42
@@ -115,7 +122,7 @@ async def fifo_rd_wr_test(
115
122
116
123
await cocotb .start (Clock (dut .wr_clk , wr_clk_period_ns , units = "ns" ).start ())
117
124
# Randomize phase shift between clocks
118
- await Timer (wr_clk_period_ns * random .random (), "ns" , round_mode = "round" )
125
+ await Timer (wr_clk_period_ns * Decimal ( random .random () ), "ns" , round_mode = "round" )
119
126
await cocotb .start (Clock (dut .rd_clk , rd_clk_period_ns , units = "ns" ).start ())
120
127
121
128
await ClockCycles (dut .wr_clk , 3 )
@@ -134,21 +141,11 @@ async def fifo_rd_wr_test(
134
141
135
142
136
143
# Generate sets of tests based on the different permutations of the possible arguments to fifo_test
137
- MAX_PERIOD_NS = 10.0
138
- MIN_PERIOD_NS = 1.0
144
+ MAX_PERIOD_NS = 10
145
+ MIN_PERIOD_NS = 1
146
+
139
147
# Generate random clk period to test between min and max
140
- RAND_WR_CLK_PERIOD_NS , RAND_RD_CLK_PERIOD_NS = [utils .get_time_from_sim_steps (
141
- # Time step must be even for cocotb clock driver
142
- steps = utils .get_sim_steps (
143
- time = Decimal (MIN_PERIOD_NS ) + (
144
- Decimal (MAX_PERIOD_NS - MIN_PERIOD_NS )
145
- * Decimal (random .random ()).quantize (Decimal ("0.00" ))
146
- ),
147
- units = "ns" ,
148
- round_mode = "round"
149
- ) & ~ 1 ,
150
- units = "ns"
151
- ) for _ in range (0 , 2 )]
148
+ RAND_WR_CLK_PERIOD_NS , RAND_RD_CLK_PERIOD_NS = [random_decimal (MAX_PERIOD_NS , MIN_PERIOD_NS ) for _ in range (2 )]
152
149
153
150
# Factory to automatically generate a set of tests based on the different permutations
154
151
# of the provided test arguments
0 commit comments