Embodiment
1.Petri net formalization definition
1.1.Petri the sufficient and necessary condition of net
Tlv triple N=(S, T; F) sufficient and necessary condition that is called direct net (abbreviation net) is:
(4) dom (F) ∪ cod (F)=S ∪ T, wherein:
S and T are called storehouse institute (place) and the transition (transition) of N, and F is a flow relation.
1.2. Qian Ji, Hou Ji
Qian Ji, back collection are inputing or outputing of T or S, and definition is arranged:
If x ∈ X is direct net N=(S, T; F) arbitrary element,
(1) (y, x) ∈ F} is called preceding collection (pre-set) or the input set of x to x={y.
(2) (x, z) ∈ F} is called back collection (post-set) or the output collection of x to x={z|.
1.3.S_ figure
If direct net N=is (S, T; F), if having
N is called S_ figure.
1.4. capacity function, sign, weight function
To direct net N=(S, T; F), note N
0=0,1,2 ... }, and N={1,2,3 ... and represent infinite with ω: ω=ω+1=ω-1=ω+ω has:
(1) K:S → N ∪ { ω } is called the capacity function of N.
(2) to given capacity function K, M:S → N
0The condition that is called the sign of N is:
(3) W:F → N is called the weight function on the N, to (x, y) ∈ F, W (x, y)=((x, y)) is called (x, y) power on to W.
1.5. elementary net system and P/T system
(1)K≡1,W≡1。This time, S_ unit was called condition, and T_ unit is called incident, and the net system is called elementary net system (EN_ system).
(2)K≡ω,W≡1。Be called the P/T system.
Here, the difference of EN_ system and P/T system just is on the capacity of S_ unit that can think that the EN_ system is the special circumstances of P/T system when K is 1, the theory that is suitable for the P/T system is also suitable in the EN_ system.
2. workflow
Be elaborated below in conjunction with 1 pair of workflow of the present invention of accompanying drawing.
Software test case generation method based on the Petri net has following software test step:
2.1. the phase one (setting up modularization Petri pessimistic concurrency control) according to measurand
Comprising: (1) is if program is structured program such as C language, because fixedly syntax format is arranged: sequential organization, construction of condition (if, switch), loop structure (while, for), then modeling respectively, the Petri pessimistic concurrency control is exactly the combination of these modules; (2) if program is 00 program such as C++, generate transition model by the constitutional diagram of half formalization language UML, dynamic figure etc., be converted into the Petri pessimistic concurrency control by uml diagram again; (3) can directly generate the Petri pessimistic concurrency control for simple requirement description or scene.
Necessary and sufficient condition according to the Petri net draws the drafting criterion that Petri nets, and is summarized as follows:
(1) S is the different elements of two classes of direct net with T, uses different diagrammatic representations respectively.S represents with zero, and T is with (or-|) expression, and F is with oriented arrow → represent that Token represents information or resource, with representing;
(2) has an element in the net at least;
(3) F only occurs between T and the S, between T or the S inside flow relation can not take place;
(4) can not have isolated T or S in the net, promptly T or S must with the F effect.
The correct foundation of Petri pessimistic concurrency control is the precondition that correct analysis and test case generate.The necessary and sufficient condition that satisfies above Petri net has just been set up the model of Petri net.
2.2. subordinate phase (collecting Petri web frame information)
2.2.1.Petri web frame information storage means
It is information gathering of Petri net and basis of structural analysis that modularization thought is set up the Petri pessimistic concurrency control.Here assembly is exactly an object, and being reflected in the modeling tool is exactly the control that instantiation is come out, and is the encapsulation to data and method.Assembly has attribute, method, incident, the interface of oneself.Attribute is the easy access person of module data.Method then is some simple and visible functions of assembly.
Each element of Petri pessimistic concurrency control (storehouse institute, transition, directed arc, Token etc.) shows with the Componentized form.S in the model, T, F or Token etc. are the instantiations of associated component, and the uniqueness of oneself is all arranged, and use Property ID separately to identify, and comprising Qian Ji, Hou Ji, title, Token number etc. simultaneously again must attribute.Collect each attribute of an element information, promptly obtain the basic structure information of Petri net: the Qian Ji of storehouse institute, transition, back collection and initialization condition etc.
2.2.2. Petri pessimistic concurrency control characteristics based on scene
Most all is that Event triggered is come control flow based on model of place, and the characteristics of this model I are that model is S_ figure.
S_ figure means that the Qian Ji of arbitrary transition and back collection all are unique, (uses the storehouse represented, i.e. t owing to need definite result set after the concrete Event triggered
), the reason that simultaneous events triggers is (promptly
T) determine also that these characteristics have determined the S_ figure characteristics of direct net N.
2.2.3. Petri pessimistic concurrency control abstract method based on scene
Node was too much when generally acknowledged shortcoming of Petri net was practical application, and leaving computer-aided tool just can not analytic system, and then the Petri net is visual and understandable, and the diagrammatic representation that is suitable for exchanging has lost meaning.Therefore need abstract model to reduce system node, thereby reach the effect of simplified model.
The first step, we define the principle of Petri pessimistic concurrency control node abstraction at the characteristics of S_ figure, and the realization details that promptly shields T_ unit masks, T_ unit
T and t
Still the directed arc with original direction connects, thereby has obtained only containing the digraph of S_ unit.The directed arc physical meaning has contained the transition incident among the figure as a result.
Second step, if do not need in the model analysis to understand the storehouse the realization details, then can have only the continuous S_ unit of single input and output directed arc to merge with 2 on above shielding principle basis, thereby reduce the node number of net system, be that following adjacency matrix analysis reduces burden.
We can obtain being used for the minimum model of analytic system node abstraction by above two steps, do not destroy the feature of Petri Netease in the descriptive system resource flow simultaneously again.Thereby, come the structural information of collection system with the net system model after simplifying.
2.2.4.Petri the data structure of web frame information
Storage organization to digraph in the net opinion has a lot of method for expressing, and commonly used have array representation (adjacency matrix), adjacency list, adjacency multilist and an orthogonal list.The representation of adjacency matrix has been represented the conversion of system library institute state more clearly, and the clear performance for the back cycle tests provides good method for expressing simultaneously, therefore selects adjacency matrix method for use.
2.3. the phase III (model analysis and checking)
The structural information of utilizing subordinate phase to obtain is in conjunction with model characteristics such as the deadlock of being analyzed the Petri pessimistic concurrency control by the theoretical respective algorithms that generates of Petri net, activity, boundedness, accessibilities.Find that mistake then needs to get back to phase one modification model.
There is different requirements in different systems to the Petri pessimistic concurrency control, just need write concrete algorithm to the specific (special) requirements of model and check various characteristics.Be the basic implementation method that example provides various character with model below based on scene.
2.3.1 set up the sign tree layout
Reachable marking tree is the basis of model analysis, but the reachable marking tree in the application of complication system at first demand side to being exactly the state explosion problem with what solve.Here we expand reachable marking tree analytical approach, set up the analytical approach of sign tree layout based on the reachable marking tree.
2.3.1.1 state explosion problem
The reachable marking tree is the tree represenation of all states of system, the accessibility between the expression state.The reachability tree representation is not perfectly, does not have perfect scheme at present on its state explosion problem of solution and provides.In the face of complication system, when needs traveled through all states, the state explosion problem had been limited to the traversal of reachability tree, and the shortcoming of the descriptive power scarcity of reachable marking tree comes out.Therefore primary is to limit the reachability tree scale within the specific limits.
2.3.1.2 the appearance main cause of state explosion problem
There are following two kinds: the one, there is the state variable of the excessive shaping type of codomain in the model, perhaps there is the quantity of state of the bigger shaping type of a plurality of codomains; The 2nd, there is the huge state variable of quantity in the model.
2.3.1.3 scheme thinking
This just requires us to define model effectively on functional structure, and that can not describe is too careful, and too careful model causes special topic to explode very much or increases the time of pattern checking.
Abstract and the simplification technology of model is exactly the method for good restraining state explosion.But model is abstract and simplify and can not solve the state explosion problem from the angle that initiatively suppresses, when model does not allow or system's merge node and the method for simplified model is worthless when need check all status informations.Here we adopt other method to cooperate the abstract and simplification technology of model, dwindle the model scale to greatest extent and do not influence system.
At model blast problem reason, there is following solution to consider.Will avoid the situation of M (s) ≠ 1 to occur in the time of at first will be from modeling, this point can be accomplished for the model based on scene.Reachability tree need be converted into overlay tree for the system of modeling difficulty and represent, i.e. the node that increases without limitation for path and sign, for example:
Each sign is all covered by successor marking on the path, and this node can merge representative with (1, w, 0).
2.3.1.4 expansion sign tree
Occur circulation when the structure problem of reachable marking tree itself makes our modeling and just can't give expression to model fully, and often there is the circulation of part of module in goal systems, the appearance of the ring of part of module makes the total system model increase rapidly and explosion phenomenon occurs just, needs us to define the sign tree (sign tree layout) of oneself.For the simplified system model, define several special joints:
Definition (1): jump out node (End Node)
System's ∑=(S, T; F, K, W, M
0),
Then S_end is for jumping out node.
What jump out that node finishes is to jump out systemic circulation, and be designated as: S_end, S_end be the back collection not, does not promptly have successor node, and S_end comes down to dead marking, generally is used for jumping out system at any time and this being identified at based on often using in the model modeling of scene is set.
Definition (2): cyclic node (Loop Node)
System's ∑=(S, T arranged; F, K, W, M
0), set of reachable markings
If M is arranged
i[t
I+1>M
I+1∧ M
j[t
J+1>M
I+1, M then
iBe cyclic node.
Sum up sign tree layout characteristics:
By start node, general node, jump out node, cyclic node is formed.
2. start from start node, end to jump out node.
3. there is one or several to flow substantially, expression standard Event stream.
4. finish BFS (Breadth First Search) by cyclic node, with basic stream supplemental tree.
5. be way flow, end to jump out node.
6. general is the node that can merge with node, adjacent and singly go into the same category node that singly goes out and merge.
7. tree is along laterally preferentially launching
8. can connect start node with jumping out node, form cyclic process, guarantee that all states can reach in the tree.
We utilize two category nodes of definition to improve the reachable marking tree, thereby have set up the sign tree layout based on the reachable marking tree.Owing to solved the infinite loop problem of model, utilized the sign tree layout just can solve the blast problem of state.Simultaneously, can utilize the part critical nature of sign tree layout analytic system, as activity, boundedness, accessibility etc.Provide concrete analysis below.
2.3.2 accessibility
Definition (accessibility):
If Petri net system ∑=(S, T arranged; F, K, W, M
0) and a sign M, there is M ∈ [M
0>then M is a reachable marking, if all can reach for all m ∈ M of ∑, just says that system's ∑ is to reach system.
Accessibility can be by the sign tree layout by leaf node M
iUpwards review to search for whether can find initial marking M step by step to its father node
0Being divided into for two steps realizes that at first traversal sign tree layout finds all M
iSign; Then, traversal M
iAll nodes are upwards reviewed, by path if find M in the path, place
0M then
iBe reachable marking.
//--the accessibility algorithm
FindFunc(v){
int Node[S_count];
int Flag=0;
NodeCopy (v, * Node[]); // obtain node Token collection
NodeFind(Node[]);
for(int i=0;i<Keep_count;i++){
Flag=NodeCmp(Node[]);
if(Flag)
Print (" M can reach ");
Else print (" M is unreachable ");
// search
NodeFind(Node[]){
for(int i=0;i<Node_count;i++){
Find (Node[i]); // relatively
Keep (i); // record
// relatively
int NodeCmp(Node[]){
for(int i=0;i<Root_count;i++){
if(Find(Node[i]));
Return 1;}}
2.3.3 it is active
Definition (activity):
To t ∈ T if to arbitrary reachable marking M ∈ [M
0>, all have the sign M ' ∈ that can reach from M [M>, make M ' [t>, then transition t is alive.If all t ∈ T are alive, just say system's ∑=(S, T; F, K, W, M
0) be alive.
Activity requires t can both carry out under all states, does not promptly have the state of being beyond one's reach, if all t all be live whole model is alive, also be circulation model.
System is not necessary for the requirement of activity, for example often needs a function that finishes or jump out system based on the model of scene, and this time, final sign M (end) was exactly a dead marking, because all can not be triggered by M (end) for t arbitrarily.Have this time two kinds of solutions to make the systemic circulation operation, allow system become system alive: a kind of is that M (end) is connected with T with M (0); Another kind is exactly to remove M (end) part.
In addition, it all is alive that system generally is not strict with each t, and it is alive perhaps just requiring the crucial t of part.Active t means that the operation of this part can carry out all the time, need set corresponding t to reachable marking like this and do specific Algorithm Analysis and judge its activity.We provide the activity that two theorems are judged concrete t.
Theorem (active theorem):
T only collects M2 behind collection M1 and one before corresponding one, if a T is that the inevitable M2 that lives can reach, promptly can be judged the activity of T by the accessibility of M2.Have necessary and sufficient condition and adequate condition as follows:
Necessary and sufficient condition: a. contains in all paths of this M2 will comprise all M; B. other nodes in the above-mentioned path, all paths at each node place have one jumping out node and will link to each other with M0 at least.
Adequate condition: jumping out node and will link to each other in all these paths with M0.
According to active theorem, can judge whether a concrete t is alive.
2.3.4 boundedness,
Definition (boundedness):
For all M ∈ [M
0>, there is positive integer k, make that M (s)≤k just says P/T_ system ∑=(S, T to all s ∈ S; F, K, W, M
0) be the system of bounded.Be also referred to as security system during k=1.
Boundedness represents that certain state is to want timely response events to handle in based on the system model of scene, and the situation of instructing and not carrying out can not occur receiving.
The reachable marking tree is the set of various states (set of reachable markings), can travel through the value condition that whole reachability tree is judged M (s) after the foundation, here can adopt the ergodic algorithm of depth-first, travel through the identification nodes of all Petri nets, read the concentrated Token number of Token that writes down in the node, compare with 1 simultaneously.
The algorithm of the node processing function in the traversal:
//--the node processing function
VisitFunc(v){
int Node[S_number];
NodeCopy (v, * Node[]); // obtain node Token collection
NodeCmp(Node[]);}
NodeCmp(Node[]){
for(int i=0;i<S_number;i++){
Cmp (Node[i]); // relatively
Keep (i); // record
2.4. quadravalence section (generation test case)
Analytical approach with the set of reachable markings of Petri net is analyzed model,, does arrangement and generates test use cases obtaining cycle tests to reachability tree or coverage diagram search and obtain identifier with depth-first or BFS (Breadth First Search) algorithm.
The main foundation of the generation of test case is exactly to identify tree layout.Use-case generates the branch following several stages and progressively generates.
1) first step, traversal sign tree layout obtains the shortest path of forward direction and is main path, and sign tree layout main path has covered all reachable markings.This has obtained the test use cases in first stage.
2) second step, the cyclic node of sign tree layout is that infinite loop begins, if each sign can be pointed to other paths again in other loop bodies in loop body, has therefore constituted very complicated test case sequence.Divide three kinds of situations:
A. initial cycle body-internal-circulation
B. many interior unidirectional circulations of loop body
C. many interior unordered circulations of loop body
For this a part of algorithm, define 3 parameter a, b, c and indicate 3 kinds of situations.
1) for the sign tree that does not have cyclic node, the path is limited, and the cycle tests number equals to jump out the number of node.
2) for the sign tree that has cyclic node, the path is unlimited, round-robin number of times multipath more is complicated more, so (parameter a, b, c) decides the path complexity according to demand, the complexity parameter designing is initially 1, test case analysis according to five-stage determines whether revising complexity, turns back to this step and regenerates the test case sequence by revising test case library in the 6th one again.
The meaning of a, b, c representative is as follows:
A: many a inner loop
B: increase b circulation
C: the circulation of (nothing) preface is arranged
According to the different values of a, b, c the cycle tests of different complexities is arranged, as shown in table 1.
Table 1 parameter value is to the influence of cycle tests
| a |
b |
c |
The description of different complexities |
| 0 |
0 |
0 |
Elementary path |
| 1 |
0 |
0 |
Increase by 1 time inner loop |
| 2 |
0 |
0 |
Increase by 2 times inner loop |
| 2 |
1 |
0 |
Transfer in another loop body by a loop body |
| 2 |
2 |
0 |
Transfer in two other loop body |
| 2 |
2 |
1 |
The unordered transfer of a plurality of loop bodies |
Reach the test case sequence that any complexity requires by change to 3 parameters.Specific algorithm just is based on the BFS (Breadth First Search) algorithm of sign tree layout, and algorithm complex can change according to demand.
2.5. five-stage (analytical test use-case)
Analyze the effectiveness of the test case that the quadravalence section obtains, here analytical approach adopts traditional statement covering, judgement covering, condition covering, condition criterion combination covering, the covering of many conditions and the covering of correction decision condition etc., the sign covering of Petri net user-defined counter, transition covering etc.
The component sign of Petri pessimistic concurrency control and transition are pairing to be the main body and the action of incident, and we define two test coverage criterias according to this: sign covers and transition cover.Simultaneously can be in conjunction with traditional test case coverage criterion.
1) sign coverage criterion
It is to cover all model identification with test case that sign covers, and sign is exactly the state of scene, and the complete covering scene of energy then this test case can contain all states.
Sign covering algorithm design: according to sign tree layout before, do not remove merge node, keep the accessible state that contains sign, utilize the sign tree layout can contain all signs, traversal sign tree layout just obtains one group of sequence, this group sequence is exactly the cycle tests of test case, and each group sequence is exactly a test case.The test use cases that obtains according to this standard comprises the sign that all can reach, and what do not contain is exactly unreachable sign, obtains use-case centralised identity number A, and total N then has the sign coverage rate as follows:
2) transition coverage criterion
Transition coverage rate algorithm design: the transition correspondence event in the model of place, and therefore good test case will cover all contingent incidents.Since the generation of transition from not sign, so have and the sign coverage rate is calculated identical method, it is exactly a test case that traversal sign tree layout obtains one group of cycle tests.
Obtain transition number B according to test use cases, sum M then has the transition coverage rate as follows:
2.6. the 6th stage (analyze and adjust test case library)
Adjust test case library according to the analysis of five-stage, test case is added, deletion, returned the effectiveness of the new test case library of five-stage analysis after revising, reach the purpose that reaches best test effect with minimum test case.
3. advantage and innovation
The present invention has following improvement and innovation to prior art:
(1) the present invention's formalization method of proposing a kind of strictness generates test case automatically.The Petri net that adopts is a kind of complete formal language, employing has the graphic language of formal semantics, than other non-formalization and the test case high conformity that generates of half formalization method, and the generation of system and the method for management software test case more complete than prior art.
(2) the present invention adopts the Componentized method to set up model, so that the analysis of the collection of model structure information and model.The method that has proposed node merging and details shielding is simultaneously come the scale of reduction system.
(3) the present invention has used Petri net theory to model analysis and checking.Petri net theory has perfect analysis theories, as deadlock, activity, boundedness, accessibility etc., by the problem that can avoid model defect to bring to a great extent to the analysis of these model properties, can carry out place mat for better generating superior in quality test case.
(4) the present invention proposes the analytical approach that identifies tree layout.Simplify the scale of reachable marking tree greatly by defining two category nodes, for model analysis provides effective method, the method by the sign tree layout solves the state explosion problem simultaneously.
(5) provided definition and algorithm among the present invention, helped to improve the efficient and the quality of test based on Petri net two class coverage rate indexs.
(6) the invention provides test case and estimate optimization mechanism.Test case not only will generate smoothly, also will satisfy the coverage rate index and the Petri net two class coverage rate indexs of conventional test methodologies.Test use cases is constantly optimized, reached test request.