DV Interview Question
DV Interview Question
NVIDIA
SYNOPSYS
QUALCOMM
AMD
INTEL
Top 50 Most Frequently
Asked Interview Questions
Prasanthi Chanda
1. Write a constraint to generate only odd numbers between 5 and
15, excluding any consecutive odd numbers Company: Intel, Synopsys
class my_rand;
rand bit [3:0] a;
constraint c1 {
a inside {[5:15]};
a % 2 == 1;
!(a == 7 || a == 9 || a == 11 || a == 13); // remove consecutive odd
}
endclass
module tb;
my_rand obj = new();
initial begin
repeat(10) begin
void'(obj.randomize());
$display("a = %0d", obj.a);
end
end
endmodule
class Packet;
virtual function void send();
$display("Sending base packet");
endfunction
endclass
module tb;
Packet pkt;
initial begin
pkt = new(); pkt.send();
pkt = new EthernetPacket(); pkt.send(); // Polymorphism
end
endmodule
class transaction;
rand bit [3:0] data;
covergroup cg;
option.per_instance = 1;
DATA: coverpoint data {
bins low = {[0:7]};
bins high = {[8:15]};
}
endgroup
function new();
cg = new();
endfunction
module tb;
transaction t;
initial begin
t = new();
repeat(10) begin
void'(t.randomize());
t.sample_data();
$display("Data = %0d", t.data);
end
end
endmodule
class transaction;
rand bit [3:0] data;
bit [7:0] id;
endclass
my_seq_agent1 seq1;
my_seq_agent2 seq2;
task body();
seq1 = my_seq_agent1::type_id::create("seq1");
seq2 = my_seq_agent2::type_id::create("seq2");
fork
seq1.start(env.agent1.sequencer);
seq2.start(env.agent2.sequencer);
join
endtask
endclass
6. How do you override a component in UVM using the factory
mechanism? Company: Nvidia, Synopsys
// write to register
reg_model.ctrl_reg.write(status, 'hA5);
// predictive update
reg_model.ctrl_reg.predict('hA5);
endtask
// In test
task build_phase(uvm_phase phase);
super.build_phase(phase);
my_config cfg = new();
uvm_config_db #(my_config)::set(this, "*", "cfg", cfg);
endtask
// In driver
task build_phase(uvm_phase phase);
super.build_phase(phase);
if (!uvm_config_db #(my_config)::get(this, "", "cfg", cfg))
`uvm_fatal("CFG", "Failed to get config")
endtask
9. Randomize an array such that it contains only even numbers
between 10 and 50, without duplicates Company: Qualcomm, Apple
class rand_array;
rand bit [7:0] arr[10];
constraint c_even {
foreach (arr[i])
arr[i] inside {[10:50]} && arr[i] % 2 == 0;
}
constraint c_unique {
unique {arr};
}
endclass
module tb;
rand_array obj = new();
initial begin
if (obj.randomize())
$display("Randomized Array = %p", obj.arr);
else
$display("Randomization Failed");
end
endmodule
// Invoke callback
uvm_callbacks#(my_driver, my_callback)::invoke("pre_drive",
this);
class tx;
rand bit [7:0] addr;
covergroup addr_cg;
coverpoint addr {
bins low = {[0:63]};
bins high = {[64:127]};
}
endgroup
function new();
addr_cg = new();
endfunction
endclass
module tb;
tx t = new();
initial begin
repeat(10) begin
void'(t.randomize());
t.addr_cg.sample();
$display("Random Addr = %0d", t.addr);
end
end
endmodule
initial begin
uvm_factory::get().set_type_override_by_type(base_tx::get_type(),
new_tx::get_type());
base_tx tx = base_tx::type_id::create("tx");
void'(tx.randomize());
$display("Polymorphic Data: %0d", tx.data);
end
13. Create a UVM sequence that generates and sends a stream of
packets with delay between each Company: Intel, Synopsys
task body();
my_transaction tx;
repeat (5) begin
tx = my_transaction::type_id::create("tx");
void'(tx.randomize());
start_item(tx);
finish_item(tx);
`uvm_info("SEQ", $sformatf("Sent tx with data=%0d", tx.data),
UVM_MEDIUM)
#10ns;
end
endtask
endclass
task test_reg();
uvm_status_e status;
uvm_reg_data_t read_val;
class sum_even;
rand bit [3:0] a, b;
constraint even_sum { (a + b) % 2 == 0; }
endclass
module tb;
sum_even obj = new();
initial begin
repeat (5) begin
void'(obj.randomize());
$display("a=%0d, b=%0d, sum=%0d", obj.a, obj.b, obj.a + obj.b);
end
end
endmodule
bit enable_monitor;
my_agent_config cfg;
function new(string name, uvm_component parent);
super.new(name, parent);
endfunction
module detect_3ones(
input logic clk, rst, in_bit,
output logic detect
);
typedef enum logic [1:0] {IDLE, ONE1, ONE2, THREE_ONES} state_t;
state_t state, next;
always_comb begin
next = IDLE;
case (state)
IDLE: next = in_bit ? ONE1 : IDLE;
ONE1: next = in_bit ? ONE2 : IDLE;
ONE2: next = in_bit ? THREE_ONES : IDLE;
THREE_ONES: next = in_bit ? THREE_ONES : IDLE;
endcase
end
class bus_tx;
rand bit [3:0] burst_len;
covergroup burst_cg;
coverpoint burst_len {
bins single = {1};
bins short = {[2:4]};
bins long = {[5:15]};
}
endgroup
function new();
burst_cg = new();
endfunction
endclass
module tb;
bus_tx tx = new();
initial begin
repeat (10) begin
void'(tx.randomize());
tx.burst_cg.sample();
$display("Burst Length = %0d", tx.burst_len);
end
end
endmodule
task body();
my_transaction tx = my_transaction::type_id::create("tx");
void'(tx.randomize());
start_item(tx);
finish_item(tx);
`uvm_info("SUB_SEQ", $sformatf("TX data: %0d", tx.data),
UVM_LOW)
endtask
endclass
task body();
repeat (3) begin
sub_seq s = sub_seq::type_id::create("sub_seq");
s.start(m_sequencer);
end
endtask
endclass
20. Write a constraint for sorting a 4-element array in ascending
order Company: Apple, Synopsys
class sort_array;
rand bit [7:0] arr[4];
constraint c_sorted {
arr[0] <= arr[1];
arr[1] <= arr[2];
arr[2] <= arr[3];
}
endclass
module tb;
sort_array s = new();
initial begin
if (s.randomize())
$display("Sorted Array = %p", s.arr);
end
endmodule
int tx_count;
22. Constraint two variables such that one is twice the other and
their sum is < 50. Company: Apple, Synopsys
class rel_constraint;
rand bit [7:0] a, b;
constraint twice {
a == 2 * b;
a + b < 50;
}
endclass
module tb;
rel_constraint obj = new();
initial begin
repeat (5) begin
void'(obj.randomize());
$display("a=%0d, b=%0d, sum=%0d", obj.a, obj.b, obj.a + obj.b);
end
end
endmodule
23. How to override a component using uvm_factory?
Company: Qualcomm, Synopsys
class base_monitor extends uvm_monitor;
`uvm_component_utils(base_monitor)
function new(string name, uvm_component parent);
super.new(name, parent); endfunction
function void build_phase(uvm_phase phase);
super.build_phase(phase);
`uvm_info("BASE_MON", "Inside base monitor", UVM_LOW)
endfunction
endclass
property p_req_min_hold;
@(posedge clk) req |=> req[*2]; // 3 cycles total
endproperty
class unique_q;
rand bit [3:0] q[$];
constraint c1 {
q.size() == 10;
foreach (q[i], q[j]) i != j -> q[i] != q[j];
foreach (q[i]) q[i] inside {[0:9]};
}
endclass
module tb;
unique_q obj = new();
initial begin
if (obj.randomize()) $display("Random Queue: %p", obj.q);
end
endmodule
26. How to connect virtual interfaces in UVM using config_db?
Company: Synopsys, Apple
// Interface
interface my_if(input logic clk);
logic req, ack;
endinterface
// Testbench Top
module tb;
logic clk = 0;
always #5 clk = ~clk;
my_if vif(clk);
initial begin
uvm_config_db #(virtual my_if)::set(null, "*", "vif", vif);
run_test("my_test");
end
endmodule
// Driver
class my_driver extends uvm_driver #(my_transaction);
`uvm_component_utils(my_driver)
virtual my_if vif;
class array_sum;
rand bit [7:0] arr[5];
constraint sum_c {
(arr.sum()) == 100;
}
endclass
module tb;
array_sum obj = new();
initial begin
repeat (5) begin
void'(obj.randomize());
$display("Array = %p, Sum = %0d", obj.arr, obj.arr.sum());
end
end
endmodule
28. How to use TLM analysis port to send data from monitor to
scoreboard? Company: Intel, Synopsys
// Monitor
class my_monitor extends uvm_monitor;
`uvm_component_utils(my_monitor)
// Scoreboard
class my_scoreboard extends uvm_scoreboard;
`uvm_component_utils(my_scoreboard)
`uvm_declare_p_sequencer(my_virtual_sequencer)
task body();
seq1 s1 = seq1::type_id::create("s1");
seq2 s2 = seq2::type_id::create("s2");
s1.start(p_sequencer.seqr1);
s2.start(p_sequencer.seqr2);
endtask
endclass
my_seqr1 seqr1;
my_seqr2 seqr2;
task body();
`uvm_info("SEQ", "Low priority sequence running", UVM_LOW)
endtask
endclass
function new;
cg = new();
endfunction
endclass
initial begin
fork
producer();
consumer();
join
end
class even_q;
rand bit [7:0] q[$];
constraint c1 {
q.size() == 5;
foreach (q[i]) q[i] % 2 == 0;
}
endclass
37. Write a covergroup that tracks transitions from IDLE -> ACTIVE
-> DONE Company: Apple, AMD
class array2D;
rand bit [7:0] arr[3][4];
constraint row_sorted {
foreach (arr[i]) {
foreach (arr[i,j]) if (j < 3) arr[i][j] <= arr[i][j+1];
}
}
endclass
class unique_array;
rand bit [3:0] a[5];
// Testbench
initial begin
unique_array u = new();
if (u.randomize())
$display("Unique values: %p", u.a);
end
40. How to use UVM callbacks in a driver to modify behavior
dynamically? Company: Intel, Qualcomm
class pkt;
rand bit [3:0] header;
rand bit [7:0] payload;
endclass
initial begin
pkt p = new();
p.header = 4'hF;
p.randomize() with { payload > 10; }; // header remains unchanged
$display("Header = %0h, Payload = %0h", p.header, p.payload);
end
42. Implement a UVM monitor that samples packets on every
positive clock Company: Intel, AMD
`uvm_component_utils(my_monitor)
class exp_queue;
rand bit [7:0] q[5];
constraint exp {
q[0] == 1;
foreach(q[i]) if (i > 0) q[i] == 2 * q[i-1];
}
endclass
initial begin
factory.set_type_override_by_type(base_seq::get_type(),
override_seq::get_type());
base_seq b = base_seq::type_id::create("b");
$display("Created object type: %s", b.get_type_name()); // Prints
override_seq
end
47. Create an assertion to check that once start is high, ack must go
high within 3 cycles Company: Intel, AMD
property ack_within_3;
@(posedge clk) start |=> ##[1:3] ack;
endproperty
// Virtual sequencer
class virt_sequencer extends uvm_sequencer;
`uvm_component_utils(virt_sequencer)
my_seqr_1 seqr1;
my_seqr_2 seqr2;
// Virtual sequence
class virt_sequence extends uvm_sequence;
`uvm_object_utils(virt_sequence)
virt_sequencer vsqr;
task body();
my_seq_1 s1 = my_seq_1::type_id::create("s1");
my_seq_2 s2 = my_seq_2::type_id::create("s2");
s1.start(vsqr.seqr1);
s2.start(vsqr.seqr2);
endtask
endclass
49. Write a SystemVerilog assertion to ensure req is high for exactly
2 cycles only Company: Intel, Apple
property req_2_cycle;
@(posedge clk) $rose(req) |-> req ##1 req ##1 !req;
endproperty
+91- 9182280927