Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tlm2 errror #33

Open
shankar-arora opened this issue Jan 13, 2016 · 0 comments
Open

tlm2 errror #33

shankar-arora opened this issue Jan 13, 2016 · 0 comments

Comments

@shankar-arora
Copy link

import uvm;
import esdl;
import std.stdio;

class test: uvm_test{
bool pass = 1;
mixin uvm_component_utils;

this(string name, uvm_component parent = null){
super(name, parent);
}

void strip_id(ref string s){
bool in_id = 0;
int i = 0;
bool p;

while(i<s.len()) {
  (s[i] >= '0' && s[i] <= '9') || s[i] == ' ')
  if(p==0)
{
  s[i]="X"; p=1;
}
  else {
s={s.substr(0,i-1),s.substr(i+1,s.len()-1)}; 
i--;
  }
  else
in_id=0;

if(s[i]=="@") { in_id=1; p=0; }
i++;   

}

void filter(ref string s1, ref string s2){
strip_id(s1);
strip_id(s2);
}

override void run_phase(uvm_phase phase){
uvm_tlm_gp obj1 = new uvm_tlm_gp("obj1"),
uvm_tlm_gp obj2 = new uvm_tlm_gp("obj2");

bool[] bits;
ubyte[] bytes;
int np, nu;

phase.raise_objection(this);

uvm_top.set_report_id_action("ILLEGALNAME", UVM_NO_ACTION);

writeln("\NUM_TRANS=%0d", NUM_TRANS);

for(int i=0; i<NUM_TRANS; i++){
  writeln("*** TRANS %0d ***",i);

  if(obj1.randomize() with {
  m_address >= 0 && m_address < 256; 
  m_length == NUM_TRANS; 
  m_data.size == m_length;
  (m_byte_enable_length % 4) == 0;
  m_byte_enable.size == m_byte_enable_length;
  foreach (m_byte_enable[i])
    m_byte_enable[i] <0  && m_byte_enable[i] > 255 };
m_streaming_width == m_length; 
} );

if(obj2.randomize() with {
m_address != obj1.m_address;
m_length == obj1.m_length-1;
m_data.size == m_length;
m_byte_enable_length <= m_length;
(m_byte_enable_length % 4) == 0;
m_byte_enable.size == m_byte_enable_length;
foreach (m_byte_enable[i])
  m_byte_enable[i] < 0 &&  m_byte_enable[i] >  255 };
  m_streaming_width == m_length; 
  } );

obj2.copy(obj1);

if(!obj1.compare(obj2))
uvm_fatal("MISCOMPARE",$sformatf("MISCOMPARE detected on generic payload!"));

{
string s1,s2;

s1 = obj1.convert2string();
s2 = obj2.convert2string();
if (s1 != s2)
  uvm_fatal("MISCOMPARE",$sformatf("convert2string different!\nobj1=%s\nobj2=%s",s1,s2))
}

s1 = obj1.sprint(uvm_default_tree_printer);
s2 = obj2.sprint(uvm_default_tree_printer);
filter(s1,s2);
if (s1 != s2)
uvm_fatal("MISCOMPARE",{"Sprint tree:\nobj1=\n",s1,"\nobj2=\n",s2});

s1 = obj1.sprint(uvm_default_line_printer);
s2 = obj2.sprint(uvm_default_line_printer);
filter(s1,s2);
if (s1 != s2)
uvm_fatal("MISCOMPARE",{"Sprint line:\nobj1=\n",s1,"\nobj2=\n",s2});
}

uvm_default_packer.use_metadata = 1;
uvm_default_packer.big_endian = i % 2;

uvm_info("TEST", format("Testing pack/unpack using %0s endian...", uvm_default_packer.big_endian) ? "big" : "little"), UVM_NONE)

obj2 = new obj("obj2");
np = obj1.pack(bits);
nu = obj2.unpack(bits);

if (!obj1.compare(obj2)) {
uvm_error("TEST", "pack/unpack MISCOMPARE");
obj1.print();
obj2.print();
}

if (np != nu) {
uvm_error("TEST", $sformatf("pack_bytes() packed %0d bits but unpacked %0d bits", np, nu))
}

void(obj1.begin_tr()){
obj1.m_data[i] = i;
obj1.end_tr();
}

uvm_info("TEST", "Checking content of packed byte stream...", UVM_LOW)
{
uvm_tlm_gp gp = new uvm_tlm_gp();

bytes = [0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae,
0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae,
0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae,
0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae,
0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae,
0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae,
0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae,
0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae,
0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae,
0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae,
0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae,
0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae,
0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae,
0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae,
0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae,
0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae,
0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae,
0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae, 0xae
];

gp.set_address(0x0011_2233_4455_7788);
gp.set_write();
gp.set_data(bytes);
gp.set_data_length(16);
gp.set_streaming_width(1);
gp.set_byte_enable(bytes); // TECHNICALLY, byte_enables elements should be 00 or FF, nothing else
gp.set_byte_enable_length(16);
gp.set_dmi_allowed(1);
gp.set_response_status(UVM_TLM_BYTE_ENABLE_ERROR_RESPONSE);

uvm_default_packer.big_endian = 0;
void(gp.pack_bytes(bytes));

  writeln("Little Endian...\n");
  foreach (bytes[i])
     writeln(",%s'h%h", (i%8) ? " ": "\n", bytes[i]);

writeln("};\n");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant