Example Code:
`include "uvm_macros.svh"
//-----------------------------------------
// module top
//---------------------------------------
module test;
import uvm_pkg::*;
//-------------------------------------
// class producer
//-------------------------------------
class producer extends uvm_component;
uvm_blocking_put_port#(int) put_port;
function new(string name, uvm_component p = null);
super.new(name,p);
put_port = new("put_port", this);
endfunction
task run_phase(uvm_phase phase);
int randval;
for(int i = 0; i < 10; i++)
begin
randval = $random % 100;
#10;
`uvm_info("producer", $sformatf("sending %4d", randval), UVM_MEDIUM)
put_port.put(randval);
end
endtask
endclass : producer
//-------------------------------------
// class consumer
//-------------------------------------
class consumer extends uvm_component;
uvm_blocking_get_port#(int) get_port;
function new(string name, uvm_component p = null);
super.new(name,p);
get_port = new("get_port", this);
endfunction
task run_phase(uvm_phase phase);
int val;
forever
begin
get_port.get(val);
`uvm_info("consumer", $sformatf("receiving %4d", val), UVM_MEDIUM)
end
endtask
endclass : consumer
//-------------------------------------
// class env
//-------------------------------------
class env extends uvm_env;
producer p;
consumer c;
uvm_tlm_fifo #(int) f;
function new(string name = "env");
super.new(name);
p = new("producer", this);
c = new("consumer", this);
f = new("fifo", this);
$display("fifo put_export: %s", f.m_name);
endfunction
function void connect_phase(uvm_phase phase);
p.put_port.connect(f.put_export);
c.get_port.connect(f.get_export);
endfunction
task run_phase(uvm_phase phase);
phase.raise_objection(this);
#1000;
phase.drop_objection(this);
endtask
endclass
// Main body of module top:
env e;
initial begin
e = new();
run_test();
//$finish;
end
endmodule // test
Simulation Report:
fifo put_export: env.fifo
UVM_INFO @ 0: reporter [RNTST] Running test ...
UVM_INFO testbench.sv(68) @ 10: env.producer [producer] sending 48
UVM_INFO testbench.sv(94) @ 10: env.consumer [consumer] receiving 48
UVM_INFO testbench.sv(68) @ 20: env.producer [producer] sending -99
UVM_INFO testbench.sv(94) @ 20: env.consumer [consumer] receiving -99
UVM_INFO testbench.sv(68) @ 30: env.producer [producer] sending -39
UVM_INFO testbench.sv(94) @ 30: env.consumer [consumer] receiving -39
UVM_INFO testbench.sv(68) @ 40: env.producer [producer] sending -9
UVM_INFO testbench.sv(94) @ 40: env.consumer [consumer] receiving -9
UVM_INFO testbench.sv(68) @ 50: env.producer [producer] sending 57
UVM_INFO testbench.sv(94) @ 50: env.consumer [consumer] receiving 57
UVM_INFO testbench.sv(68) @ 60: env.producer [producer] sending 57
UVM_INFO testbench.sv(94) @ 60: env.consumer [consumer] receiving 57
UVM_INFO testbench.sv(68) @ 70: env.producer [producer] sending -71
UVM_INFO testbench.sv(94) @ 70: env.consumer [consumer] receiving -71
UVM_INFO testbench.sv(68) @ 80: env.producer [producer] sending -14
UVM_INFO testbench.sv(94) @ 80: env.consumer [consumer] receiving -14
UVM_INFO testbench.sv(68) @ 90: env.producer [producer] sending 61
UVM_INFO testbench.sv(94) @ 90: env.consumer [consumer] receiving 61
UVM_INFO testbench.sv(68) @ 100: env.producer [producer] sending 29
UVM_INFO testbench.sv(94) @ 100: env.consumer [consumer] receiving 29
UVM_INFO /apps/vcsmx/vcs/P-2019.06-1//etc/uvm-1.2/src/base/uvm_objection.svh(1276) @ 1000: reporter [TEST_DONE] 'run' phase is ready to proceed to the 'extract' phase
UVM_INFO /apps/vcsmx/vcs/P-2019.06-1//etc/uvm-1.2/src/base/uvm_report_server.svh(894) @ 1000: reporter [UVM/REPORT/SERVER]
--- UVM Report Summary ---
** Report counts by severity
UVM_INFO : 23
UVM_WARNING : 0
UVM_ERROR : 0
UVM_FATAL : 0
** Report counts by id
[RNTST] 1
[TEST_DONE] 1
[UVM/RELNOTES] 1
[consumer] 10
[producer] 10
* * * S i m u l a t i o n R e p o r t * * *
Time: 1000 ns
CPU Time: 0.520 seconds; Data structure size: 0.2Mb
Fri May 15 07:09:30 2020
Comments
Post a Comment