UVM Object Compare

2023-11-02
UVM

範例跟uvm_object copy一樣,先把obj1的資料都clone到obj2,然後先用compare function比較一下結果,結果是資料完全相同,接著刻意把obj2的int_var這個變數的值改掉,然後再比較一次obj1和obj2,就可以看見miscompare的error info。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import uvm_pkg::*;
`include "uvm_macros.svh"

typedef enum {FALSE, TRUE} e_bool;

class Packet extends uvm_object;
bit[31:0] addr;

`uvm_object_utils_begin(Packet)
`uvm_field_int(addr, UVM_DEFAULT)
`uvm_object_utils_end

function new(string name = "Packet");
super.new(name);
addr = $random;
endfunction
endclass

class Object extends uvm_object;
e_bool bool;
bit[3:0] bit_var;
int int_var;
string str;
Packet pkt;

`uvm_object_utils_begin(Object)
`uvm_field_enum(e_bool, bool, UVM_DEFAULT)
`uvm_field_int(bit_var, UVM_DEFAULT)
`uvm_field_int(int_var, UVM_DEFAULT)
`uvm_field_string(str, UVM_DEFAULT)
`uvm_field_object(pkt, UVM_DEFAULT)
`uvm_object_utils_end

function new(string name = "Object");
super.new(name);
str = name;
bit_var = $random;
int_var= $random;
pkt = Packet::type_id::create("pkt");
endfunction
endclass

class base_test extends uvm_test;
`uvm_component_utils(base_test)
function new(string name = "base_test", uvm_component parent = null);
super.new(name, parent);
endfunction

function void build_phase(uvm_phase phase);
Object obj1 = Object::type_id::create("obj1");
Object obj2;
// Object obj2 = Object::type_id::create("obj2");
obj1.print();
//obj2.print();
//obj2.copy(obj1);
$cast(obj2, obj1.clone());
`uvm_info("base_test", "After copy", UVM_LOW)
obj2.print();

if (obj2.compare(obj1))
`uvm_info("base_test", "obj1 and obj2 are same", UVM_LOW)
else
`uvm_info("base_test", "obj1 and obj2 are different", UVM_LOW)

obj2.int_var = 32'h12345678;
`uvm_info("base_test", "modify object2.int_var", UVM_LOW)

if (obj2.compare(obj1))
`uvm_info("base_test", "obj1 and obj2 are same", UVM_LOW)
else
`uvm_info("base_test", "obj1 and obj2 are different", UVM_LOW)
endfunction
endclass

module tb;
initial begin
$display("start");
run_test("base_test");
end
endmodule

Output

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# start
# UVM_INFO @ 0: reporter [RNTST] Running test base_test...
# -------------------------------------
# Name Type Size Value
# -------------------------------------
# obj1 Object - @473
# bool e_bool 32 FALSE
# bit_var integral 4 'h4
# int_var integral 32 'hc0895e81
# str string 6 Object
# pkt Packet - @474
# addr integral 32 'h8484d609
# -------------------------------------
# UVM_INFO .\uvm_object_compare.sv(59) @ 0: uvm_test_top [base_test] After copy
# -------------------------------------
# Name Type Size Value
# -------------------------------------
# obj1 Object - @475
# bool e_bool 32 FALSE
# bit_var integral 4 'h4
# int_var integral 32 'hc0895e81
# str string 6 Object
# pkt Packet - @477
# addr integral 32 'h8484d609
# -------------------------------------
# UVM_INFO .\uvm_object_compare.sv(63) @ 0: uvm_test_top [base_test] obj1 and obj2 are same
# UVM_INFO .\uvm_object_compare.sv(68) @ 0: uvm_test_top [base_test] modify object2.int_var
# UVM_INFO @ 0: reporter [MISCMP] Miscompare for obj1.int_var: lhs = 'h12345678 : rhs = 'hc0895e81
# UVM_INFO @ 0: reporter [MISCMP] 1 Miscompare(s) for object obj1@473 vs. obj1@475
# UVM_INFO .\uvm_object_compare.sv(73) @ 0: uvm_test_top [base_test] obj1 and obj2 are different
#

Using do_compare

和print/copy一樣,compare一樣可以用do_compare客製化自己想要compare的東西,目前還沒打算練習這個。