Interview Questions on Systemverilog

I faced conflict to answer for the below Queries in interview,Please give knowledge in the below listed Queries:

  1. I have a multi dimensional array. don’t know the number of dimensional it has. How to know the number of dimensions of multi dimensional array?
  2. How to check whether randomization is successful or not without using assertions??
  3. How to pick a element which is in queue from random index?
  4. Write a program to choose elements randomly from queue.No element should be reputed until all elements are chosen. Queue may have elements repeated?
  5. Explain how you debugged randomization failure?
  6. I have a object of a class. I would like to print the class name. How to print the class name using object handle?
  7. What is the need to implement explicitly a copy() method inside a transaction, when we can simple assign one object to other?
  8. How to avoid the race condition between 2 program block?

Some quick thoughts:-
1. use $dimensions 

2. void'(obj.randomize())
   if(!obj.randomize()) //preferred method
   Try to avoid using assertions for checking randomization 

3. use $urandom_range() in place of array index 

4. use $urandom_range() with randc 

5. Randomization fail when the constraints conflict , so i would first analysis the constraints that are conflicting 

6. This can be done easily in UVM using get_name() or get_type_name() , which would return the string passed to new. To access using object in C++ one can use standard  library
std::cout<<typeid(obj).name(). Not sure if this supports in SV.


7. If you assign an obj to other only the handles will be copied , so deep copy needs to be implemented  

8.Is the question correct ? The program block is used to avoid race condition b/t the Tb and DUT since program block executes in reactive region whereas module executes in active region .

In reply to bl4ckp3rl :

Mostly correct

$dimensions
2.
if(!obj.randomize()) $info(“success”) else $error(“failure”);

3.
queue[$urandom_range(queue.size()-1)]

4. -

class C;
int q[$];
randc int index;
constraint select { index inside {[0:queue.size()-1]}; }
  1. Tool specific solver debugging features

$typename(handle)
7. Deep-copy versus shallow copy
8. Race conditions between DUT to TB, DUT to DUT, TB to TB, can all be avoided with non-blocking assigments, and other basic synchronizing mechanisms like clocking blocks. Do not use program blocks.