CN103294595B - A kind of software repair based on genetic algorithm - Google Patents

A kind of software repair based on genetic algorithm Download PDF

Info

Publication number
CN103294595B
CN103294595B CN201310196339.9A CN201310196339A CN103294595B CN 103294595 B CN103294595 B CN 103294595B CN 201310196339 A CN201310196339 A CN 201310196339A CN 103294595 B CN103294595 B CN 103294595B
Authority
CN
China
Prior art keywords
test case
program
individuality
node
individual
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201310196339.9A
Other languages
Chinese (zh)
Other versions
CN103294595A (en
Inventor
段振华
戚云霞
田聪
张南
王小兵
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Xidian University
Original Assignee
Xidian University
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Xidian University filed Critical Xidian University
Priority to CN201310196339.9A priority Critical patent/CN103294595B/en
Publication of CN103294595A publication Critical patent/CN103294595A/en
Application granted granted Critical
Publication of CN103294595B publication Critical patent/CN103294595B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

A kind of software repair based on genetic algorithm, it includes, A. it is abstract syntax tree construction by program representation to be repaired, and generate test use cases, described test case is concentrated and is comprised positive test case and negative testing use-case, described positive test case is the test case of correct execution in a program, and described negative testing use-case is that program performs abnormal end or draws the test case of error result;B. replicating original program obtains M copies of programs, and M individuality is carried out mutation operation, arranges the maximum evolutionary generation that program is evolved;C. determining fitness function, using described invariant as the invariant constraint calculating fitness, to each individual all test cases that perform, test case number and invariant constraint that calculating is passed through keep number, by calculating the fitness value obtaining each individuality;D. genetic manipulation: the genetic manipulation carried out individual in every generation population is included: variation, intersection and selection;E. end condition judges。

Description

A kind of software repair based on genetic algorithm
Technical field
The invention belongs to field of software engineering, it is proposed that a kind of self-repairing method that can be used for software error reparation。
Background technology
In recent years, along with the development of modern software, software is more and more important for enterprise, individual, and the quantity of software gets more and more, and function is more and more abundanter, and scale is also more and more huger。Any one team is impossible to software to be made perfection in the designing and developing of software, and even there is also more fault, and this is accomplished by software developer and these faults are repaired。Existing software fault restorative procedure has:
Recovery block method:
The recovery policy of fault generally has two kinds: forward direction recovers and backward recovery。Recovery block method adopts backward recovery policy。It provides main piece and several standby blocks with identical function, and a block is exactly one and performs complete program segment, and first main piece put into operation, carries out Acceptance Test after terminating, and without by Acceptance Test, system is run by a standby block after in-situ FTIR spectroelectrochemitry。This process can repeat to and exhaust all of standby block, or certain program mal behavior is beyond it is anticipated that thus cause expendable consequence。Should ensure that the independence realized between main piece and standby block during design, it is to avoid the generation of relevant error, make the general character mistake between main piece and standby block be preferably minimized limit。Acceptance testing program completes fault detection capability, and recovery block method is general character by the fault of itself, it is therefore necessary to ensure its correctness。
N version program method for designing:
N version program designs, and is the fault masking technology of a kind of static state, adopts the strategy that forward direction recovers, and its design philosophy is to perform a calculating by N number of program with identical function simultaneously, and result is selected by majority voting。Wherein N part program by different people's independent design, must use diverse ways, and different design languages, different development environments and instrument realize。Purpose is to reduce N version software probability of relevant error on voting point。Further, since various different editions executed in parallel, sometimes perform even in different computers, it is necessary to solve stationary problem each other。
Above several method is all based on redundancy principle, so considerably increase the workload of programmer, in addition other method is through manual debugging, first input test information progressively detects errors present, analyzing error reason again and find out recovery scenario, this manual software repair is not only consuming time but also require great effort。
On the other hand, along with the progress and development of Genetic Algorithm Technology, genetic algorithm has been widely used a lot of field。
Owing to overall search strategy and the optimizing search method of genetic algorithm do not rely on gradient information or other supplementary knowledge when calculating, and have only to affect the object function of the direction of search and corresponding fitness function, so genetic algorithm provides a kind of general framework solving complication system problem, it does not rely on the specific field of problem, the kind of problem there is very strong robustness, so being widely used in many science。At present, some main application fields of genetic algorithm have:
Function optimization: function optimization is the classic applications field of genetic algorithm, also being the genetic algorithm conventional case that carries out performance evaluation, research worker has constructed the test function of various complex form: continuous function and discrete function, convex and concave functions, low-dimensional function and high-dimension function and unimodal function and Solving Multimodal Function etc.。, multi-model, multiobject function optimization problem non-linear for some, solve with other optimization method is more difficult, and genetic algorithm can obtain good result easily。
Combinatorial Optimization: along with the increase of problem scale, the search volume of combinatorial optimization problem also sharply increases, and sometimes is difficult to obtain optimal solution by enumerative technique in current calculating。Problem to this kind of complexity, seeks on satisfactory solution it have been realized that main attention should be placed on, and genetic algorithm is one of best instrument seeking this satisfactory solution。It was verified that genetic algorithm is highly effective for the np problem in Combinatorial Optimization。Such as genetic algorithm has been succeeded application in solving traveling salesman problem, knapsack problem, bin packing, figure partition problem etc.。
Additionally, genetic algorithm also in production scheduling problems, automatically control, robotics, image processing, artificial life, obtain in genetic coding and machine learning etc. and use widely。
Summary of the invention
It is an object of the invention to overcome the defect of above software repair, it is provided that a kind of software repair based on genetic algorithm, evolution algorithm is applied in software fault reparation, to realize the automatization that software fault is repaired。
During realization the technical scheme is that Genetic Programming Paradigm: A applies to software fault to be repaired, and invariant constraint is added when calculating fitness function, thus the mistake existed in repair procedure under the premise keeping program original function, a kind of software repair based on genetic algorithm, it comprises the following steps
A. it is abstract syntax tree construction by program representation to be repaired, and generate test use cases, described test case is concentrated and is comprised positive test case and negative testing use-case, described positive test case is the test case of correct execution in a program, described negative testing use-case is that program performs abnormal end or draws the test case of error result, and original program is performed positive test case, generate the invariant in described program by invariant Core Generator;
B. replicating original program obtains M copies of programs, M individuality carries out mutation operation, original program and described M copies of programs as the initial population in genetic algorithm;The maximum evolutionary generation that program is evolved is set;
C. determining fitness function, using described invariant as the invariant constraint calculating fitness, to each individual all test cases that perform, test case number and invariant constraint that calculating is passed through keep number, by calculating the fitness value obtaining each individuality;
D. genetic manipulation:
The genetic manipulation carried out individual in every generation population is included: variation, intersection and selection;It includes, and individuality in population carries out mutation operation and the operation that intersects, then calculates fitness individual in described population according to the method for step C, selects M individuality to obtain population of future generation;
E. end condition judges:
According to M individual fitness value in a new generation population, if the fitness value having individuality is 1, namely by all test cases, and maintain whole invariant constraints, then hit pay dirk reparation, terminates calculating;
Judging whether to reach maximum evolutionary generation, if reaching, terminating calculating;
Otherwise, D-E step is repeated。
On the basis of technique scheme, an executable state or control flow structure in each node correspondence program of described abstract syntax tree。
On the basis of technique scheme, each state node of described abstract syntax tree corresponding ordered pair table < s, a ws>, s refers to the sequence number of node, wsReferring to the weights that this node is corresponding, and node each in abstract syntax tree is arranged weights, its weights installation warrants is:
If only positive test case has access to, weight ws=1.0;
If only negative testing use-case has access to, weight ws=0.0;
If positive and negative test case all has access to, weight ws=vp/(vp+vn);
Wherein vpRepresent the number of times that this node is had access to by positive test case, vnRepresent the number of times that this node is had access to by negative testing use-case。
On the basis of technique scheme, program uses program code when calculating fitness, and test case number and the invariant of maintenance that execution program computation passes through retrain number。
On the basis of technique scheme, described fitness function is made up of two parts: first calculate individual by test case number account for the ratio of all test cases, the more many fitness values of the test case passed through are more big;It addition, calculate the number that individual invariant constraint keeps, fitness function is:
f ( x i ) = | { t &Element; T | ( x i ) Pass ( t ) } | | T | - | c p - c i | | c p |
Wherein, f (xi) represent individual xiFitness;
T represents that test use cases, t refer to test case therein;
(xi) the individual x of Pass (t) expressioniThe number of test case is represented by test case t, | T |;
cpRepresent the original individuality invariant constraint number when performing positive test case;
ciRepresent individual xiPerform positive test case time and cpConsistent invariant constraint number。
On the basis of technique scheme, described variation includes acting on the node in the path that negative testing use-case has access to and positive test case does not have access to, according to the mutation probability individuality to choosing, the node that its weights are minimum carries out mutation operation, mutation operation includes the deletion to this node, insert new node or exchange with it with new node, and described new node takes from other node in individuality。
On the basis of technique scheme, described intersection includes generating two cross points by random algorithm, exchanges the node between two cross points。
On the basis of technique scheme, described intersection includes two cross methods, and described two cross methods include each individuality and will intersect with original individuality, and optional other individualities of each individuality intersect。
On the basis of technique scheme, described selection includes the individuality after intersecting is carried out fitness calculating, selects M the individual and original individual entrance next generation that fitness value is high。
Due to the principle of locality of program, the program fault processing mode in certain position can obtain from the combination of other nodes of locations of program。Present invention utilizes the convergence of the uncertain search of genetic algorithm and genetic algorithm, genetic algorithm is used for the reparation of software fault。This method greatly reduces the workload in software is repaired of developer, is a kind of effective, software repair that automaticity is high。
Accompanying drawing explanation
Fig. 1 is the flow chart of the software repair based on genetic algorithm that the present invention proposes。
Detailed description of the invention
Enforcement step with reference to Fig. 1 present invention is as follows:
(1) program representation: be abstract syntax tree construction by program representation, in wherein said abstract syntax tree, each node is an executable statement or one-stage control flow structure。Evolutional operation is positioned on the node of error checking use-case execution route。
Choose one group of test use cases T so that it is all functions of energy test program as far as possible。Test case is concentrated and is comprised positive test case and negative testing use-case。Described positive test case is the test case of correct execution in a program, and described negative testing use-case is that program performs abnormal end or draws the test case of error result。
By invariant Core Generator, program is performed positive test case, the invariant in generation program, uses when the invariant of generation is constrained in calculating fitness value as invariant。
(2) initialize: arranging evolutionary generation enumerator t=0, maximum evolutionary generation MAX, replicating original program obtains M copies of programs, M individuality carries out mutation operation, original program and described M copy as initial population。Described mutation operation includes the deletion to node, interpolation or exchange。
(3) fitness calculates: determining fitness function, the quality of fitness function determines the quality of evolution result。Described fitness function is made up of two parts: first calculate individual by test case number;Then, the number that individual invariant constraint keeps is calculated。
Fitness function is:
f ( x i ) = | { t &Element; T | ( x i ) Pass ( t ) } | | T | - | c p - c i | | c p |
Wherein, f (xi) represent individual xiFitness;
T represents that test use cases, t refer to test case therein;
(xi) the individual x of Pass (t) expressioniThe number of test case is represented by test case t, | T |;
cpRepresent the original individuality invariant constraint number when performing positive test case;
ciRepresent individual xiPerform positive test case time and cpConsistent invariant constraint number。
(4) variation: overall situation mutation probability is pm, carry out mutation operation according to the node that weights in the mutation probability individuality to choosing are relatively low, randomly choose and it is deleted, add new node or select corresponding node to exchange with it。Described new node takes from other node of abstract syntax tree。
(5) intersecting: crossover probability is 1.0, in per generation, the individuality of each existence will carry out intersection operation, adopts two point to intersect, namely the node between two cross points is swapped, and the selection in described cross point adopts stochastic generation。The operation that intersects adopts form two kinds different:
Each individuality always first intersects with original individuality;
Optional other individuality of each individuality intersects with it。
(6) select: method according to (3) calculates the individual fitness value obtained after intersecting, select M the individual and original individuality that fitness value is higher, obtain population of future generation;
(7) conditional judgment: according to M individual fitness value in a new generation population, it is first determined whether the fitness value having individuality is 1, if having, namely by all test cases, and maintain whole invariant constraints, then hit pay dirk reparation, terminates calculating;Otherwise, it is determined whether reach maximum evolutionary generation, if reaching, terminating calculating, now having obtained the program that part is repaired;Otherwise, step (4) to (7) is repeated。
For a person skilled in the art, can technical scheme as described above and design, make other various corresponding changes and deformation, and all these change and deformation all should belong within the protection domain of the claims in the present invention。

Claims (8)

1. the software repair based on genetic algorithm, it is characterised in that: it comprises the following steps,
A. it is abstract syntax tree construction by program representation to be repaired, and generate test use cases, described test case is concentrated and is comprised positive test case and negative testing use-case, described positive test case is the test case of correct execution in a program, described negative testing use-case is that program performs abnormal end or draws the test case of error result, and original program is performed positive test case, the invariant in described program is generated by invariant Core Generator, each state node of described abstract syntax tree corresponding ordered pair table < s, a ws>, s refers to the sequence number of node, wsReferring to the weights that this node is corresponding, and node each in abstract syntax tree is arranged weights, its weights installation warrants is:
If only positive test case has access to, weight ws=1.0;
If only negative testing use-case has access to, weight ws=0.0;
If positive and negative test case all has access to, weight ws=vp/(vp+vn);
Wherein vpRepresent the number of times that this node is had access to by positive test case, vnRepresent the number of times that this node is had access to by negative testing use-case;
B. replicating original program obtains M copies of programs, M individuality carries out mutation operation, original program and described M copies of programs as the initial population in genetic algorithm;The maximum evolutionary generation that program is evolved is set;
C. determine fitness function, using described invariant as the invariant constraint calculating fitness, to all test cases of each individual execution, calculate the invariant constraint number of test case number and the maintenance passed through, by calculating the fitness value obtaining each individuality;
D. genetic manipulation:
The genetic manipulation carried out individual in every generation population is included: variation, intersection and selection;It includes, and individuality in population carries out mutation operation and the operation that intersects, then calculates fitness individual in described population according to the method for step C, selects M individuality to obtain population of future generation;
E. end condition judges:
According to M individual fitness value in a new generation population, if the fitness value having individuality is 1, namely by all test cases, and maintain whole invariant constraints, then hit pay dirk reparation, terminates calculating;
Judging whether to reach maximum evolutionary generation, if reaching, terminating calculating;
Otherwise, D-E step is repeated。
2. a kind of software repair based on genetic algorithm according to claim 1, it is characterised in that: an executable state or control flow structure in each node correspondence program of described abstract syntax tree。
3. a kind of software repair based on genetic algorithm according to claim 1, it is characterised in that: program uses program code when calculating fitness, and test case number and the invariant of maintenance that execution program computation passes through retrain number。
4. a kind of software repair based on genetic algorithm according to claim 1, it is characterized in that: described fitness function is made up of two parts: first calculate individual by test case number account for the ratio of all test cases, the more many fitness values of the test case passed through are more big;It addition, calculate the number that individual invariant constraint keeps,
Fitness function is:
f ( x i ) = | { t &Element; T | ( x i ) P a s s ( t ) } | | T | - | c p - c i | | c p |
Wherein, f (xi) represent individual xiFitness;
T represents that test use cases, t refer to test case therein;
(xi) the individual x of Pass (t) expressioniThe number of test case is represented by test case t, | T |;
cpRepresent the original individuality invariant constraint number when performing positive test case;
ciRepresent individual xiPerform positive test case time and cpConsistent invariant constraint number。
5. a kind of software repair based on genetic algorithm according to claim 1, it is characterized in that: described variation includes acting on the node in the path that negative testing use-case has access to and positive test case does not have access to, according to the mutation probability individuality to choosing, the node that its weights are minimum carries out mutation operation, mutation operation includes the deletion to this node, insert new node or exchange with it with new node, and described new node takes from other node in individuality。
6. a kind of software repair based on genetic algorithm according to claim 1, it is characterised in that: described intersection includes generating two cross points by random algorithm, exchanges the node between two cross points。
7. a kind of software repair based on genetic algorithm according to claim 6, it is characterized in that: described intersection includes two cross methods, described two cross methods include each individuality and will intersect with original individuality, and optional other individualities of each individuality intersect。
8. a kind of software repair based on genetic algorithm according to claim 1, it is characterised in that: described selection includes the individuality after intersecting is carried out fitness calculating, selects M the individual and original individual entrance next generation that fitness value is high。
CN201310196339.9A 2013-05-23 2013-05-23 A kind of software repair based on genetic algorithm Active CN103294595B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201310196339.9A CN103294595B (en) 2013-05-23 2013-05-23 A kind of software repair based on genetic algorithm

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201310196339.9A CN103294595B (en) 2013-05-23 2013-05-23 A kind of software repair based on genetic algorithm

Publications (2)

Publication Number Publication Date
CN103294595A CN103294595A (en) 2013-09-11
CN103294595B true CN103294595B (en) 2016-06-22

Family

ID=49095513

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201310196339.9A Active CN103294595B (en) 2013-05-23 2013-05-23 A kind of software repair based on genetic algorithm

Country Status (1)

Country Link
CN (1) CN103294595B (en)

Families Citing this family (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106886467B (en) * 2017-02-24 2019-02-01 电子科技大学 Preferred method is tested based on the multitask of grouping-synthesis multi-target evolution
CN108897688A (en) * 2018-06-29 2018-11-27 西安电子科技大学 Method for test examples design based on BWDSP processor
CN111444079B (en) * 2019-01-16 2022-09-30 河南工业大学 Software defect repairing method and device
CN110750449A (en) * 2019-09-19 2020-02-04 中山大学 Test-driven webpage component function extraction method
CN111737120B (en) * 2020-06-15 2022-09-23 河南工业大学 Software defect repairing method and device
CN113672503A (en) * 2021-08-03 2021-11-19 中移(杭州)信息技术有限公司 Test case generation method, system, terminal device and storage medium
CN113778876A (en) * 2021-09-09 2021-12-10 南京大学 Method and device for generating program variation of source code level
CN114153742A (en) * 2021-12-10 2022-03-08 深圳前海微众银行股份有限公司 Unit testing method, unit testing device, electronic equipment and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5754760A (en) * 1996-05-30 1998-05-19 Integrity Qa Software, Inc. Automatic software testing tool
CN101853202A (en) * 2010-05-28 2010-10-06 浙江大学 Test case autogeneration method based on genetic algorithm and weighted matching algorithm
CN102226913A (en) * 2011-05-23 2011-10-26 中国科学院软件研究所 Method for automatically generating Bug repair plan and Bug repair method

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5754760A (en) * 1996-05-30 1998-05-19 Integrity Qa Software, Inc. Automatic software testing tool
CN101853202A (en) * 2010-05-28 2010-10-06 浙江大学 Test case autogeneration method based on genetic algorithm and weighted matching algorithm
CN102226913A (en) * 2011-05-23 2011-10-26 中国科学院软件研究所 Method for automatically generating Bug repair plan and Bug repair method

Also Published As

Publication number Publication date
CN103294595A (en) 2013-09-11

Similar Documents

Publication Publication Date Title
CN103294595B (en) A kind of software repair based on genetic algorithm
CN107783758B (en) A kind of intelligence contract engineering method
US8181163B2 (en) Program synthesis and debugging using machine learning techniques
Codish et al. Twenty-five comparators is optimal when sorting nine inputs (and twenty-nine for ten)
Patelli et al. Opencossan 2.0: an efficient computational toolbox for risk, reliability and resilience analysis
CN105868116A (en) Semantic mutation operator based test case generation and optimization method
CN106294148A (en) C programmer software verification method based on escape character transition system and device
Mishra et al. Test case optimization and prioritization based on multi-objective genetic algorithm
Codish et al. Sorting nine inputs requires twenty-five comparisons
CN102799960B (en) The concurrent service flow process method for detecting abnormality of data-orlented model
CN110275825A (en) A kind of software reliability estimation method of Component- Based Development influence power
CN110297765B (en) Early evaluation method for software reliability
CN113490920A (en) Method, device and system for evaluating code design quality
CN104335161B (en) Efficient evaluation of network robustness with a graph
Malhotra et al. A new metric for predicting software change using gene expression programming
Souri Formal specification and verification of a data replication approach in distributed systems
Li et al. Reliability assurance for deep neural network architectures against numerical defects
Elfaki et al. Investigating inconsistency detection as a validation operation in software product line
Ai et al. What ruined your cake: impacts of code modifications on bug distribution
Matsumoto et al. Consistency Verification of UML Sequence Diagrams Modeling Wireless Sensor Networks
CN109240737A (en) A kind of method and system of the packing and issuing in big data platform
Brameret Assessment of reliability indicators from automatically generated partial Markov chains
Jing et al. A method for test case generation by improved genetic algorithm based on static structure of procedure
Hou Integrated reliability and availability aanalysis of networks with software failures and hardware failures
Ma et al. SLOGAN: SDC probability estimation using structured graph attention network

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant