1 |
4 |
vladimirar |
//----------------------------------------------------------------------
|
2 |
|
|
// Copyright 2014-2015 SyoSil ApS
|
3 |
|
|
// All Rights Reserved Worldwide
|
4 |
|
|
//
|
5 |
|
|
// Licensed under the Apache License, Version 2.0 (the
|
6 |
|
|
// "License"); you may not use this file except in
|
7 |
|
|
// compliance with the License. You may obtain a copy of
|
8 |
|
|
// the License at
|
9 |
|
|
//
|
10 |
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
11 |
|
|
//
|
12 |
|
|
// Unless required by applicable law or agreed to in
|
13 |
|
|
// writing, software distributed under the License is
|
14 |
|
|
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
15 |
|
|
// CONDITIONS OF ANY KIND, either express or implied. See
|
16 |
|
|
// the License for the specific language governing
|
17 |
|
|
// permissions and limitations under the License.
|
18 |
|
|
//----------------------------------------------------------------------
|
19 |
|
|
/// Class which implements the in order compare algorithm
|
20 |
|
|
class cl_syoscb_compare_io extends cl_syoscb_compare_base;
|
21 |
|
|
//-------------------------------------
|
22 |
|
|
// UVM Macros
|
23 |
|
|
//-------------------------------------
|
24 |
|
|
`uvm_object_utils(cl_syoscb_compare_io)
|
25 |
|
|
|
26 |
|
|
//-------------------------------------
|
27 |
|
|
// Constructor
|
28 |
|
|
//-------------------------------------
|
29 |
|
|
extern function new(string name = "cl_syoscb_compare_io");
|
30 |
|
|
|
31 |
|
|
//-------------------------------------
|
32 |
|
|
// Compare API
|
33 |
|
|
//-------------------------------------
|
34 |
|
|
extern virtual function void compare();
|
35 |
|
|
extern function void compare_do();
|
36 |
|
|
endclass: cl_syoscb_compare_io
|
37 |
|
|
|
38 |
|
|
function cl_syoscb_compare_io::new(string name = "cl_syoscb_compare_io");
|
39 |
|
|
super.new(name);
|
40 |
|
|
endfunction: new
|
41 |
|
|
|
42 |
|
|
/// Compare API: Mandatory overwriting of the base class' compare method.
|
43 |
|
|
/// Currently, this just calls do_compare() blindly
|
44 |
|
|
function void cl_syoscb_compare_io::compare();
|
45 |
|
|
// Here any state variables should be queried
|
46 |
|
|
// to compute if the compare should be done or not
|
47 |
|
|
this.compare_do();
|
48 |
|
|
endfunction: compare
|
49 |
|
|
|
50 |
|
|
/// Compare API: Mandatory overwriting of the base class' do_compare method.
|
51 |
|
|
/// Here the actual in order compare is implemented.
|
52 |
|
|
///
|
53 |
|
|
/// The algorithm gets the primary queue and then loops over all other queues to see if
|
54 |
|
|
/// it can find primary item as the first item in all of the other queues. If so then the items
|
55 |
|
|
/// are removed from all queues. If not then a UVM error is issued.
|
56 |
|
|
function void cl_syoscb_compare_io::compare_do();
|
57 |
|
|
string primary_queue_name;
|
58 |
|
|
cl_syoscb_queue primary_queue;
|
59 |
|
|
cl_syoscb_queue_iterator_base primary_queue_iter;
|
60 |
|
|
string queue_names[];
|
61 |
|
|
int unsigned secondary_item_found[string];
|
62 |
|
|
bit compare_continue = 1'b1;
|
63 |
|
|
bit compare_result = 1'b0;
|
64 |
|
|
cl_syoscb_item primary_item;
|
65 |
|
|
|
66 |
|
|
// Initialize state variables
|
67 |
|
|
primary_queue_name = this.get_primary_queue_name();
|
68 |
|
|
this.cfg.get_queues(queue_names);
|
69 |
|
|
|
70 |
|
|
primary_queue = this.cfg.get_queue(primary_queue_name);
|
71 |
|
|
if(primary_queue == null) begin
|
72 |
|
|
`uvm_fatal("QUEUE_ERROR", $sformatf("[%s]: cmp-io: Unable to retrieve primary queue handle", this.cfg.get_scb_name()));
|
73 |
|
|
end
|
74 |
|
|
|
75 |
|
|
primary_queue_iter = primary_queue.create_iterator();
|
76 |
|
|
|
77 |
|
|
`uvm_info("DEBUG", $sformatf("[%s]: cmp-io: primary queue: %s", this.cfg.get_scb_name(), primary_queue_name), UVM_FULL);
|
78 |
|
|
`uvm_info("DEBUG", $sformatf("[%s]: cmp-io: number of queues: %0d", this.cfg.get_scb_name(), queue_names.size()), UVM_FULL);
|
79 |
|
|
|
80 |
|
|
// Outer loop loops through all
|
81 |
|
|
while(!primary_queue_iter.is_done()) begin
|
82 |
|
|
primary_item = primary_queue_iter.get_item();
|
83 |
|
|
|
84 |
|
|
`uvm_info("DEBUG", $sformatf("[%s]: cmp-io: Now comparing primary transaction:\n%s", this.cfg.get_scb_name(), primary_item.sprint()), UVM_FULL);
|
85 |
|
|
|
86 |
|
|
// Clear list of found slave items before starting new inner loop
|
87 |
|
|
secondary_item_found.delete();
|
88 |
|
|
|
89 |
|
|
// Inner loop through all queues
|
90 |
|
|
foreach(queue_names[i]) begin
|
91 |
|
|
`uvm_info("DEBUG", $sformatf("[%s]: cmp-io: Looking at queue: %s", this.cfg.get_scb_name(), queue_names[i]), UVM_FULL);
|
92 |
|
|
|
93 |
|
|
if(queue_names[i] != primary_queue_name) begin
|
94 |
|
|
cl_syoscb_queue secondary_queue;
|
95 |
|
|
cl_syoscb_queue_iterator_base secondary_queue_iter;
|
96 |
|
|
cl_syoscb_item sih;
|
97 |
|
|
|
98 |
|
|
`uvm_info("DEBUG", $sformatf("[%s]: cmp-io: %s is a secondary queue - now comparing", this.cfg.get_scb_name(), queue_names[i]), UVM_FULL);
|
99 |
|
|
|
100 |
|
|
// Get the secondary queue
|
101 |
|
|
secondary_queue = this.cfg.get_queue(queue_names[i]);
|
102 |
|
|
|
103 |
|
|
if(secondary_queue == null) begin
|
104 |
|
|
`uvm_fatal("QUEUE_ERROR", $sformatf("[%s]: cmp-io: Unable to retrieve secondary queue handle", this.cfg.get_scb_name()));
|
105 |
|
|
end
|
106 |
|
|
|
107 |
|
|
`uvm_info("DEBUG", $sformatf("[%s]: cmp-io: %0d items in queue: %s", this.cfg.get_scb_name(), secondary_queue.get_size(), queue_names[i]), UVM_FULL);
|
108 |
|
|
|
109 |
|
|
// Get an iterator for the secondary queue
|
110 |
|
|
secondary_queue_iter = secondary_queue.create_iterator();
|
111 |
|
|
|
112 |
|
|
// Only do the compare if there are actually an item in the secondary queue
|
113 |
|
|
if(!secondary_queue_iter.is_done()) begin
|
114 |
|
|
// Get the first item from the secondary queue
|
115 |
|
|
sih = secondary_queue_iter.get_item();
|
116 |
|
|
|
117 |
|
|
if(sih.compare(primary_item) == 1'b1) begin
|
118 |
|
|
secondary_item_found[queue_names[i]] = secondary_queue_iter.get_idx();
|
119 |
|
|
`uvm_info("DEBUG", $sformatf("[%s]: cmp-io: Secondary item found at index: %0d:\n%s", this.cfg.get_scb_name(), secondary_queue_iter.get_idx(), sih.sprint()), UVM_FULL);
|
120 |
|
|
end else begin
|
121 |
|
|
`uvm_error("COMPARE_ERROR", $sformatf("[%s]: cmp-io: Item:\n%s\nfrom primary queue: %s not found in secondary queue: %s. Found this item in %s instead:\n%s", this.cfg.get_scb_name(), primary_item.sprint(), primary_queue_name, queue_names[i], queue_names[i], sih.sprint()))
|
122 |
|
|
|
123 |
|
|
// The first element was not a match => break since this is an in order compare
|
124 |
|
|
break;
|
125 |
|
|
end
|
126 |
|
|
end else begin
|
127 |
|
|
`uvm_info("DEBUG", $sformatf("[%s]: cmp-io: %s is empty - skipping", this.cfg.get_scb_name(), queue_names[i]), UVM_FULL);
|
128 |
|
|
end
|
129 |
|
|
|
130 |
|
|
if(!secondary_queue.delete_iterator(secondary_queue_iter)) begin
|
131 |
|
|
`uvm_fatal("QUEUE_ERROR", $sformatf("[%s]: cmp-io: Unable to delete iterator from secondaery queue: %s", this.cfg.get_scb_name(), queue_names[i]));
|
132 |
|
|
end
|
133 |
|
|
end else begin
|
134 |
|
|
`uvm_info("DEBUG", $sformatf("[%s]: cmp-io: %s is the primary queue - skipping", this.cfg.get_scb_name(), queue_names[i]), UVM_FULL);
|
135 |
|
|
end
|
136 |
|
|
end
|
137 |
|
|
|
138 |
|
|
// Only start to remove items if all slave items are found (One from each slave queue)
|
139 |
|
|
if(secondary_item_found.size() == queue_names.size()-1) begin
|
140 |
|
|
string queue_name;
|
141 |
|
|
cl_syoscb_item pih;
|
142 |
|
|
|
143 |
|
|
// Get the item from the primary queue
|
144 |
|
|
pih = primary_queue_iter.get_item();
|
145 |
|
|
|
146 |
|
|
`uvm_info("DEBUG", $sformatf("[%s]: cmp-io: Found match for primary queue item :\n%s", this.cfg.get_scb_name(), pih.sprint()), UVM_FULL);
|
147 |
|
|
|
148 |
|
|
// Remove from primary
|
149 |
|
|
if(!primary_queue.delete_item(primary_queue_iter.get_idx())) begin
|
150 |
|
|
`uvm_error("QUEUE_ERROR", $sformatf("[%s]: cmp-io: Unable to delete item idx %0d from queue %s",
|
151 |
|
|
this.cfg.get_scb_name(), primary_queue_iter.get_idx(), primary_queue.get_name()));
|
152 |
|
|
end
|
153 |
|
|
|
154 |
|
|
// Remove from all secondaries
|
155 |
|
|
while(secondary_item_found.next(queue_name)) begin
|
156 |
|
|
cl_syoscb_queue secondary_queue;
|
157 |
|
|
|
158 |
|
|
// Get the secondary queue
|
159 |
|
|
secondary_queue = this.cfg.get_queue(queue_name);
|
160 |
|
|
|
161 |
|
|
if(secondary_queue == null) begin
|
162 |
|
|
`uvm_fatal("QUEUE_ERROR", $sformatf("[%s]: cmp-io: Unable to retrieve secondary queue handle", this.cfg.get_scb_name()));
|
163 |
|
|
end
|
164 |
|
|
|
165 |
|
|
if(!secondary_queue.delete_item(secondary_item_found[queue_name])) begin
|
166 |
|
|
`uvm_error("QUEUE_ERROR", $sformatf("[%s]: cmp-io: Unable to delete item idx %0d from queue %s",
|
167 |
|
|
this.cfg.get_scb_name(), secondary_item_found[queue_name], secondary_queue.get_name()));
|
168 |
|
|
end
|
169 |
|
|
end
|
170 |
|
|
end
|
171 |
|
|
|
172 |
|
|
// Call .next() blindly since we do not care about the
|
173 |
|
|
// return value, since we might be at the end of the queue.
|
174 |
|
|
// Thus, .next() will return 1'b0 at the end of the queue
|
175 |
|
|
void'(primary_queue_iter.next());
|
176 |
|
|
end
|
177 |
|
|
|
178 |
|
|
if(!primary_queue.delete_iterator(primary_queue_iter)) begin
|
179 |
|
|
`uvm_fatal("QUEUE_ERROR", $sformatf("[%s]: cmp-io: Unable to delete iterator from primary queue: %s", this.cfg.get_scb_name(), primary_queue_name));
|
180 |
|
|
end
|
181 |
|
|
endfunction: compare_do
|