简体   繁体   中英

What is the difference between deep_copy and gen keeping in Specman?

can someone tell me what is the difference between coping one transaction(item) to the another like in examples bellow ( add_method_port_1 and add_method_port_2 ):

add_method_port_1 (added_item: item_s) is {
    var new_item: new_item_s;
    gen new_item keeping { 
        it.my_trans_s == added_item.as_a(t_trans_s); 
    };  
};

add_method_port_2 (added_item: item_s) is {
    var new_item : new_item_s = deep_copy(added_item.as_a(t_trans_s));
};

Where new_item_s looks like:

struct new_item_s like item_s {
    %my_trans_s: t_trans_s;
};

Thanks, Andrija

In this specific example, assuming that new_item_s has only one field my_trans_s, there is no difference in outcome.

In practice, the meaning and the goal of "gen keeping" and deep_copy is quite different:

  • gen keeping, even with '==' constraints, practically assignments, means random-constraint generating an item executing iGen logic engine; if this is a struct then pre_generate and post_generate methods are invoked, and all the fields not mentioned in 'keeping {}' block are also randomly generated according to existing constraints and their type properties. It is usually used to create a new item for which only some properties are known.
  • deep_copy creates an exact copy (up to some minor nuances) of the given struct, and if it has fields which are also structs - copy of all connected graph topology. There is no random generation, no special methods, no logical engine executed. Usually it used to capture the data at some point for later analysis.

In other words, if the assumption "new_item_s has only one field my_trans_s" is wrong, the result are going to be very much different.

Actually, the results of the two methods are different even if the assumption mentioned in Rodion's answer does hold.

With the first method, new_item points to the same my_trans_s object as the original added_item , because the constraint it.my_trans_s == added_item.as_a(t_trans_s) means pointer equality.

With the second method, new_item points to a copy of the original my_trans_s , because deep_copy copies everything recursively.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM