0% found this document useful (0 votes)
29 views2 pages

Uvmmethods

This document defines UVM classes for objects and tests. The my_object class defines random fields including an embedded temp_class. The my_test class creates my_object instances, randomizes their fields, and tests copying, cloning, and comparing the objects.

Uploaded by

Neeraja Mathew
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views2 pages

Uvmmethods

This document defines UVM classes for objects and tests. The my_object class defines random fields including an embedded temp_class. The my_test class creates my_object instances, randomizes their fields, and tests copying, cloning, and comparing the objects.

Uploaded by

Neeraja Mathew
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

`include "uvm_macros.

svh"
import uvm_pkg::*;

typedef enum{RED, GREEN, BLUE} color_type;

class temp_class extends uvm_object;


rand bit [7:0] tmp_addr;
rand bit [7:0] tmp_data;

function new(string name = "temp_class");


super.new(name);
endfunction

`uvm_object_utils_begin(temp_class)
`uvm_field_int(tmp_addr, UVM_ALL_ON)
`uvm_field_int(tmp_data, UVM_ALL_ON)
`uvm_object_utils_end
endclass

class my_object extends uvm_object;


rand int value;
string names;
rand color_type colors;
rand byte data[4];
rand bit [7:0] addr;
rand temp_class tmp;

`uvm_object_utils_begin(my_object)
`uvm_field_int(value, UVM_ALL_ON)
`uvm_field_string(names, UVM_ALL_ON)
`uvm_field_enum(color_type, colors, UVM_ALL_ON)
`uvm_field_sarray_int(data, UVM_ALL_ON)
`uvm_field_int(addr, UVM_ALL_ON)
`uvm_field_object(tmp, UVM_ALL_ON)
`uvm_object_utils_end

function new(string name = "my_object");


super.new(name);
tmp = new();
this.names = "UVM";
endfunction
endclass

class my_test extends uvm_test;

`uvm_component_utils(my_test)

my_object obj_A, obj_B;


bit packed_data_bits[];
byte unsigned packed_data_bytes[];
int unsigned packed_data_ints[];

my_object unpack_obj;

function new(string name = "my_test", uvm_component parent = null);


super.new(name, parent);
endfunction

function void build_phase(uvm_phase phase);


super.build_phase(phase);
obj_A = my_object::type_id::create("obj_A", this);
obj_B = my_object::type_id::create("obj_B", this);

`uvm_info("Test","Initial", UVM_NONE);
assert(obj_A.randomize());
obj_A.print();
assert(obj_B.randomize());
obj_B.print();

`uvm_info("Test","Copy A to B", UVM_NONE);


obj_B.copy(obj_A);
obj_A.print();
obj_B.print();

`uvm_info("Test","Reset", UVM_NONE);
assert(obj_A.randomize());
obj_A.print();
assert(obj_B.randomize());
obj_B.print();

`uvm_info("Test","Clone A to B", UVM_NONE);


$cast(obj_B,obj_A.clone());
obj_A.print();
obj_B.print();

if(obj_B.compare(obj_A))
`uvm_info("Test","Compare A & B", UVM_NONE);

endfunction
endclass

module tb_top;
initial begin
run_test("my_test");
end
endmodule

You might also like