SyoSil ApS UVM Scoreboard  1.0.3.0
cl_scb_test_iterator_unit_tests_md5.svh
1 /// Test that md5-iterators using cl_syoscb_cfg#ordered_next conform to spec.
3  //-------------------------------------
4  // Non randomizable variables
5  //-------------------------------------
6 
7 
8  //-------------------------------------
9  // UVM Macros
10  //-------------------------------------
11  `uvm_component_utils_begin(cl_scb_test_iterator_unit_tests_md5)
12 
13  `uvm_component_utils_end
14 
15  //-------------------------------------
16  // Constructor
17  //-------------------------------------
18  function new(string name = "cl_scb_test_iterator_unit_tests_md5", uvm_component parent = null);
19  super.new(name, parent);
20  endfunction: new
21 
22  //-------------------------------------
23  // Functions
24  //-------------------------------------
25  extern function void pre_build();
26  extern task main_phase(uvm_phase phase);
27  extern function void check_hash_collision_iteration();
28  extern function void check_hash_collision_iteration_no_ordered_next();
29 
30 
32 
33 function void cl_scb_test_iterator_unit_tests_md5::pre_build();
34  super.pre_build();
35  this.syoscb_cfgs.syoscb_cfg[0].set_queue_type(pk_syoscb::SYOSCB_QUEUE_MD5);
36  this.syoscb_cfgs.syoscb_cfg[0].set_ordered_next(1'b1);
37 endfunction: pre_build
38 
39 //If two items have the same hash, and ordered_next=0, do we correctly iterate over the queue?
40 function void cl_scb_test_iterator_unit_tests_md5::check_hash_collision_iteration_no_ordered_next();
41  //Test is very similar to test where ordered_next=1, but since we don't know which items show up first,
42  //we must modify the test a little bit
43  cl_tb_seq_item items[4];
45 
46  //Disable cloning to we can modify items after insertion
47  this.syoscb_cfgs.syoscb_cfg[0].set_disable_clone(1'b1);
48  this.syoscb_cfgs.syoscb_cfg[0].set_ordered_next(1'b0);
49 
50  //We generate items with same contents to make sure they have same hash
51  foreach(items[i]) begin
52  items[i] = cl_tb_seq_item::type_id::create("item");
53  end
54  items[0].int_a = 0;
55  items[1].int_a = 0;
56  items[2].int_a = 2;
57  items[3].int_a = 2;
58  foreach(items[i]) begin
59  this.scb_env.syoscb[0].add_item("Q1", "P1", items[i]);
60  end
61 
62 
63  //After inserting items, we modify items[1] and items[3] to simulate a hash collision.
64  items[1].int_a=1;
65  items[3].int_a=3;
66 
67  //Now, we use an iterator to check that we can find all of the values in there
68  iter = this.syoscb_cfgs.syoscb_cfg[0].get_queue("Q1").create_iterator();
69  void'(iter.first());
70  //Check if first two items are consecutive
71  begin
72  cl_tb_seq_item found_item1, found_item2;
73  found_item1 = this.get_next(iter);
74  found_item2 = this.get_next(iter);
75  if(found_item2.int_a != found_item1.int_a+1) begin
76  `uvm_error("ITER_HASH_NEXT", $sformatf("ordered_next=0, first two items did not match. first.int_a=%0d, second.int_a=%0d", found_item1.int_a, found_item2.int_a))
77  end
78  end
79 
80  begin
81  cl_tb_seq_item found_item1, found_item2;
82  found_item1 = this.get_next(iter);
83  found_item2 = this.get_next(iter);
84 
85  if(found_item2.int_a != found_item1.int_a+1) begin
86  `uvm_error("ITER_HASH_NEXT", $sformatf("ordered_next=0, last two items did not match. first.int_a=%0d, second.int_a=%0d", found_item1.int_a, found_item2.int_a))
87  end
88  end
89 
90  //Reset iterator to first
91  void'(iter.first());
92  //Reset back to last
93  void'(iter.last());
94  //Traverse queue in reverse order.
95  begin
96  cl_tb_seq_item found_item1, found_item2;
97  found_item1 = this.get_previous(iter);
98  found_item2 = this.get_previous(iter);
99 
100  if(found_item1.int_a != found_item2.int_a+1) begin
101  `uvm_error("ITER_HASH_NEXT", $sformatf("ordered_next=0, last two items did not match. first.int_a=%0d, second.int_a=%0d", found_item1.int_a, found_item2.int_a))
102  end
103  end
104  begin
105  cl_tb_seq_item found_item1, found_item2;
106  found_item1 = this.get_previous(iter);
107  found_item2 = this.get_previous(iter);
108 
109  if(found_item1.int_a != found_item2.int_a+1) begin
110  `uvm_error("ITER_HASH_NEXT", $sformatf("ordered_next=0, last two items did not match. first.int_a=%0d, second.int_a=%0d", found_item1.int_a, found_item2.int_a))
111  end
112  end
113 
114  //Tests passed, flush queues
115  void'(this.syoscb_cfgs.syoscb_cfg[0].get_queue("Q1").delete_iterator(iter));
116  `uvm_info("ITER_HASH_NEXT", "Iterator traversal with hash collisions and ordered_next=0 passed tests", UVM_LOW)
117  this.scb_env.syoscb[0].flush_queues_all();
118 
119  this.syoscb_cfgs.syoscb_cfg[0].set_ordered_next(1'b1);
120 
121 endfunction: check_hash_collision_iteration_no_ordered_next
122 
123 //If two items have the hash hash, and ordered next=1, do we correctly iterate over the queue?
124 function void cl_scb_test_iterator_unit_tests_md5::check_hash_collision_iteration();
125  cl_tb_seq_item items[4];
127 
128  this.syoscb_cfgs.syoscb_cfg[0].set_disable_clone(1'b1);
129 
130  //We generate items with same contents to make sure they have same hash
131  foreach(items[i]) begin
132  items[i] = cl_tb_seq_item::type_id::create("item");
133  end
134  items[0].int_a = 0;
135  items[1].int_a = 0;
136  items[2].int_a = 2;
137  items[3].int_a = 2;
138  foreach(items[i]) begin
139  this.scb_env.syoscb[0].add_item("Q1", "P1", items[i]);
140  end
141 
142 
143  //After inserting items, we modify items[1] and items[3] to simulate a hash collision.
144  items[1].int_a=1;
145  items[3].int_a=3;
146 
147  //Now, we use an iterator to check that we can find all of the values in there
148  iter = this.syoscb_cfgs.syoscb_cfg[0].get_queue("Q1").create_iterator();
149  //Reset iterator to first, check if it maches
150  void'(iter.first());
151 
152  //Traverse forward over all items
153  while(iter.has_next()) begin
154  cl_tb_seq_item found_item;
155 
156  found_item = this.get_next(iter);
157  if(found_item.int_a != iter.previous_index()) begin
158  `uvm_error("ITER_HASH_NEXT", $sformatf("Item at index %0d did not have expected int_a value, got %0d", iter.previous_index(), found_item.int_a))
159  end
160  void'(iter.next());
161  end
162 
163  //Reset iterator to first
164  void'(iter.first());
165  //Reset back to last
166  void'(iter.last());
167  //Traverse queue in reverse order. First, we check item at last index for correctness
168  begin
169  cl_tb_seq_item found_item;
170 
171  found_item = this.get_previous(iter);
172  if(found_item.int_a != 3) begin
173  `uvm_error("ITER_HASH_NEXT", $sformatf("Item at index %0d did not have expected int_a value, got %0d", iter.next_index(), found_item.int_a))
174  end
175  end
176 
177  //Perform traversal in reverse order
178  while(iter.has_previous()) begin
179  cl_tb_seq_item found_item;
180 
181  found_item = this.get_previous(iter);
182  if(found_item.int_a != iter.next_index()) begin
183  `uvm_error("ITER_HASH_NEXT", $sformatf("Item at index %0d did not have expected int_a value, got %0d", iter.next_index(), found_item.int_a))
184  end
185  end
186 
187  //Tests passed, flush queues
188  void'(this.syoscb_cfgs.syoscb_cfg[0].get_queue("Q1").delete_iterator(iter));
189  `uvm_info("ITER_HASH_NEXT", "Iterator traversal with hash collisions and ordered_next=1 passed tests", UVM_LOW)
190  this.scb_env.syoscb[0].flush_queues_all();
191 
192 endfunction: check_hash_collision_iteration
193 
194 task cl_scb_test_iterator_unit_tests_md5::main_phase(uvm_phase phase);
195  phase.raise_objection(this);
196  super.main_phase(phase);
197 
198  this.check_hash_collision_iteration();
199  this.check_hash_collision_iteration_no_ordered_next();
200 
201  //Verify that flushing and iterating works correctly when ordered_next = 0
202  this.syoscb_cfgs.syoscb_cfg[0].set_ordered_next(1'b0);
203  for(int i=0; i<10; i++) begin
204  cl_tb_seq_item item = cl_tb_seq_item::type_id::create("item");
205  item.int_a = i;
206  this.scb_env.syoscb[0].add_item("Q1", "P1", item);
207  end
208  this.check_flush();
209  this.scb_env.syoscb[0].flush_queues_all();
210 
211  phase.drop_objection(this);
212 endtask: main_phase
Test containing a series of unit tests to ensure that all iterators conform to spec.
Queue iterator base class defining the iterator API used for iterating over queues.
Test that md5-iterators using cl_syoscb_cfg::ordered_next conform to spec.

Project: SyoSil ApS UVM Scoreboard, Revision: 1.0.3.0

Copyright 2014-2022 SyoSil ApS
All Rights Reserved Worldwide

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
doxygen
Doxygen Version: 1.8.14
Generated with IDV SV Filter Version: 2.6.3
Fri Sep 2 2022 14:37:44
Find a documentation bug? Report bugs to: scoreboard@syosil.com