One other thought, perhaps because the file name is “test1.sv” rather than “test1.svh”, that the compiler is instructed to create an object of the class automatically?
Short answer:
(step 1) you called `uvm_component_utils(test1) in your test class declaration - this registers a named wrapper class with the UVM factory at static initialization time. That wrapper can be looked up by name in the factory’s table of known components and objects, and instantiated on demand
(step 2) meanwhile, you called UVM’s global run_test(test_name) entry point, which instantiates the singleton class uvm_root, calls its run_test(test_name), which instantiates the singleton class uvm_factory, checks the command line for a +UVM_TESTNAME=x plusarg, and then calls the uvm_factory to create an instance of the required test_name component, before finally starting UVM phasing which does the rest.
That’s what run_test does. It creates an instance of test1 from the factory. See the Cookbook here and here for more information. We usually recommend that you call run_test() with no arguments and specify the test name on the command line via +UVM_TESTNAME.
the other puzzling thing I see is that the “test” instantiates the “env”.
so, if I have multiple tests, each one should instantiate the “env”, but only one of the tests will actually get created by the factory.
I would have thought the env would be instantiated somewhere outside the test, and then the test could connect to it via the factory ::connect functions.
That way the env is always created independent of the test.
Maybe its a strange question, but things are so separated and sequestered in UVM, I’m surprized that “tests” and “env” are not also separated.
You’re right. It is a strange question. ;-)
Due to the way the build_phase() process works, each component, starting with the test, must instantiate any children in the build_phase() method. If you want the env to be separate from your test, you could pass in the type of your env via a config to the test, and have the test pull it and instantiate it, but that’s a bit clunky.