In reply to UVM_learner6:
I have 3 sequence items, with a rand [7:0] id; in all 3 of them.
During a test run, I want all of them to be unique id values. Even though I have declared them as “randc” in each Sequence Item, it only avoid repetition of “id” for that particular sequence item. How can I add a constraint for them all to have unique values? id in sequence 1 should NEVER show up for sequence 2.
Please help.
I tried something based on your question, and I wanted to share it with you.
module automatic test;
class seq1;
rand bit [7:0] port_id;
constraint port_id_c {
soft port_id inside {[1:100]};
}
endclass : seq1
class seq2;
rand bit [7:0] port_id;
constraint port_id_c {
soft port_id inside {[1:100]};
}
endclass : seq2
class seq3;
rand bit [7:0] port_id;
constraint port_id_c {
soft port_id inside {[1:100]};
}
endclass : seq3
initial begin
bit [7:0] port_ids[$];
seq1 s1; seq2 s2; seq3 s3;
s1 = new();
s2 = new();
s3 = new();
repeat (10) begin
while (port_ids.size() != 3) begin
s1.randomize();
s2.randomize();
s3.randomize();
if (!(s1.port_id inside {s2.port_id, s3.port_id}) || (s2.port_id inside {s1.port_id, s3.port_id})
|| (s3.port_id inside {s2.port_id, s2.port_id})) begin
port_ids.push_back(s1.port_id);
port_ids.push_back(s2.port_id);
port_ids.push_back(s3.port_id);
end
end
$display("The unique port_ids are %p", port_ids);
//drive the port_ids
//Then delete the queue for the next iteration
port_ids = {};
end
//Now let'say you want to drive the seq1 = 3, seq2 = 4, seq3 = 5 to cover some corner condition
//You will do
s1.randomize() with {port_id == 3;};
s2.randomize() with {port_id == 4;};
s3.randomize() with {port_id == 5;};
port_ids.push_back(s1.port_id);
port_ids.push_back(s2.port_id);
port_ids.push_back(s3.port_id);
$display("The unique port_ids are %p", port_ids);
//drive the ports based on ids.
//Then detete the queue.
port_ids = {};
//Now let's say you want the port_ids to be between 101:255
repeat (10) begin
while (port_ids.size() != 3) begin
s1.randomize() with {port_id inside {[101:255]};};
s2.randomize() with {port_id inside {[101:255]};};
s3.randomize() with {port_id inside {[101:255]};};
if (!(s1.port_id inside {s2.port_id, s3.port_id}) || (s2.port_id inside {s1.port_id, s3.port_id})
|| (s3.port_id inside {s2.port_id, s2.port_id})) begin
port_ids.push_back(s1.port_id);
port_ids.push_back(s2.port_id);
port_ids.push_back(s3.port_id);
end
end
$display("The unique port_ids are %p", port_ids);
//drive the port_ids
//Then delete the queue for the next iteration
port_ids = {};
end
end
endmodule : test
The outputs are as following:
The unique port_ids are '{'h4d, 'h3f, 'h5c}
The unique port_ids are '{'h3c, 'h4, 'h59}
The unique port_ids are '{'h4, 'h49, 'h34}
The unique port_ids are '{'h24, 'h39, 'h50}
The unique port_ids are '{'h12, 'h3f, 'h2f}
The unique port_ids are '{'h2e, 'h1c, 'h53}
The unique port_ids are '{'hc, 'h59, 'h2}
The unique port_ids are '{'h1f, 'h17, 'he}
The unique port_ids are '{'h30, 'h1f, 'h39}
The unique port_ids are '{'h4d, 'h4d, 'h5f}
The unique port_ids are '{'h3, 'h4, 'h5}
The unique port_ids are '{'hb2, 'hec, 'hc6}
The unique port_ids are '{'h9e, 'h73, 'h71}
The unique port_ids are '{'hce, 'h8d, 'h9c}
The unique port_ids are '{'h76, 'hba, 'hb1}
The unique port_ids are '{'hf1, 'hb5, 'hdf}
The unique port_ids are '{'hf5, 'hb5, 'h8a}
The unique port_ids are '{'he9, 'h6b, 'hd3}
The unique port_ids are '{'hdc, 'h91, 'hfb}
The unique port_ids are '{'hb9, 'hd9, 'hd4}
The unique port_ids are '{'he6, 'h88, 'hf7}