Jump to content

Assigning a handle in the env


Recommended Posts

I have a package and inside the package there is a task . There is an env abc whose handle abc_env is created in my_env and the connections are done in my_env. I would like to use a handle of abc abc_env2 in the task inside my package but assign the properties of abc_env1 to it. How can i assign the environment's handle ( abc_env1) to abc_env2 in my_env file?

file 1

package xyz

.

.

task pqr()

abc abc_env2;

..............

endtask

endpackage

file 2

class my_env extends uvm_env

abc abc_env1;

void build function

abc_env1 = abc::type_id::create("abc_env1",this);

endfunction

.

.

.

.

.

endclass

Link to comment
Share on other sites

Hello Meenu,

It is not clear to me what exactly you are trying to do but you should be able to pass the class handle as an argument to the pqr task. If it is going to be an extended class then you would want to cast it. Otherwise you can just assign. Here is a simple example I was able to get working.

import uvm_pkg::*;
`include "uvm_macros.svh"
package xyz;

class abc extends uvm_env;
 `uvm_component_utils(abc)
 function new(input string name="abc", uvm_component parent = null);
   super.new(name, parent);
 endfunction : new  
endclass : abc

task pqr(uvm_component env_comp);
 abc abc_env2;
 if ($cast(abc_env2, env_comp))
   $display("Success:env_comp=%0d  abc_env2=%0d", env_comp, abc_env2);
 else $display("Failure");
endtask

endpackage

module top();
import xyz::*;
class my_env extends uvm_env;
 abc abc_env1;
 `uvm_component_utils(my_env)
 function void build_phase(uvm_phase phase);
   super.build_phase(phase);
   abc_env1 = abc::type_id::create("abc_env1", this);
 endfunction : build_phase
 function new(input string name="my_env", uvm_component parent = null);
   super.new(name, parent);
 endfunction : new  
 task run_phase(uvm_phase phase);
    xyz::pqr(abc_env1);
 endtask : run_phase
endclass

class my_test extends uvm_test;
 my_env myenv;
 function new(input string name="my_test", uvm_component parent = null);
   super.new(name, parent);
 endfunction : new  
 `uvm_component_utils(my_test)
 function void build_phase(uvm_phase phase);
   super.build_phase(phase);
    myenv = my_env::type_id::create("myenv", this);
 endfunction : build_phase
endclass : my_test

initial begin
  run_test("my_test");
end
endmodule : top

I hope it helps.

Kathleen

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...