CN103294595A - Genetic algorithm based software repair method - Google Patents

Genetic algorithm based software repair method Download PDF

Info

Publication number
CN103294595A
CN103294595A CN2013101963399A CN201310196339A CN103294595A CN 103294595 A CN103294595 A CN 103294595A CN 2013101963399 A CN2013101963399 A CN 2013101963399A CN 201310196339 A CN201310196339 A CN 201310196339A CN 103294595 A CN103294595 A CN 103294595A
Authority
CN
China
Prior art keywords
test case
individual
program
node
individuality
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.)
Granted
Application number
CN2013101963399A
Other languages
Chinese (zh)
Other versions
CN103294595B (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

Images

Abstract

A genetic algorithm based software repair method includes steps of A), signifying a to-be-repaired program to be an abstract syntax tree structure, generating a test case suite comprising positive test cases which are correctly executed in the program and negative test cases which are abnormally ended or produce error results during program execution; B), copying original programs to acquire M program copies, subjecting the M program copies to mutation operation and setting the biggest evolutionary algebra; determining fitness function, taking invariants as invariant constraints to calculate fitness, executing all test cases to each individual, calculating number of passed test cases and maintained number of the invariant constraints, and acquiring fitness values of each individual by calculating; D), subjecting genetic operation of the individual of each generation population comprising variation, intersection and selection; E), terminating conditional judgment.

Description

A kind of software restorative procedure based on genetic algorithm
Technical field
The invention belongs to field of software engineering, proposed a kind of self-repairing method that software error is repaired that can be used for.
Background technology
In recent years, along with the continuous development of modern software, software was more and more important for enterprise, individual, and the quantity of software is more and more, and function is more and more abundanter, and scale is also more and more huger.Any one team all can not do software perfectly in the designing and developing of software, even also more fault can occur, and this just needs the software developer that these faults are repaired.Existing software fault restorative procedure has:
The recovery block method:
The recovery policy of fault generally has two kinds: forward direction recovers with the back to recovery.The recovery block method adopts the back to recovery policy.It provides main piece and the several reserve piece with identical function, and a piece is exactly the program segment of a complete, and main piece at first puts into operation, carries out Acceptance Test after the end, if not by Acceptance Test, system is moved by a reserve piece after recover at the scene.This process can repeat to and exhaust all reserve pieces, and perhaps certain program mal behavior has exceeded expectation, thereby causes expendable consequence.Should guarantee to realize the independence between main piece and the reserve piece during design, avoid the generation of relevant error, make the general character mistake between main piece and the reserve piece drop to bottom line.Acceptance testing program is finished fault detection capability, and the fault of itself is general character for the recovery block method, therefore, must guarantee its correctness.
N version program method for designing:
The design of N version program is a kind of fault masking technology of static state, the strategy that adopts forward direction to recover, and its design philosophy is to carry out a calculating simultaneously with N the program with identical function, the result selects by majority voting.Wherein N part program must be used diverse ways by different people's independent design, different design languages, and different development environment and instruments are realized.Purpose is to reduce the probability of N version software relevant error on the voting point.In addition, because various different editions executed in parallel are carried out sometimes even in different computing machines, must solve stationary problem each other.
The front several method all is based on redundant principle, increased programmer's workload so greatly, in addition other method is exactly by artificial debugging, elder generation's input test information progressively detects errors present, the profiling error reason is found out recovery scenario again, and this manual software restorative procedure 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 applied to a lot of fields.
Because the whole search strategy of genetic algorithm and optimization searching method do not rely on gradient information or other supplementary knowledge when calculating, and only need influence objective function and the corresponding fitness function of the direction of search, so genetic algorithm provides a kind of general framework of finding the solution the complication system problem, it does not rely on the specific field of problem, kind to problem has very strong robustness, so be 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 be the case commonly used that genetic algorithm is carried out performance evaluation, the researchist has constructed the trial function of various complex form: continuous function and discrete function, convex function and concave function, low-dimensional function and higher-dimension function and unimodal function and multimodal function etc., multi-model non-linear for some, multiobject function optimization problem, with other optimization method difficulty find the solution, and genetic algorithm can obtain result preferably easily.
Combinatorial Optimization: along with the increase of problem scale, the search volume of combinatorial optimization problem also sharply increases, and is difficult to obtain optimum solution with enumerative technique sometimes in present calculating.To this class complicated problems, people have recognized to be placed on main energy and have sought on the satisfactory solution, and genetic algorithm is one of best instrument of seeking this satisfactory solution.Facts have proved that genetic algorithm is very effective for the np problem in the Combinatorial Optimization.The for example genetic algorithm application of having succeeded at aspects such as finding the solution traveling salesman problem, knapsack problem, bin packing, figure partition problem.
In addition, genetic algorithm has also obtained to use widely at aspects such as production scheduling problems, control automatically, robotics, image processing, artificial life, genetic coding and machine learning.
Summary of the invention
The objective of the invention is to overcome the defective of above software restorative procedure, a kind of software restorative procedure based on genetic algorithm is provided, evolution algorithm is applied in the software fault reparation, with the robotization that realizes that software fault is repaired.
Realize that technical scheme of the present invention is that the genetic program method for designing is applied in the software fault reparation, and interpolation invariant constraint when calculating fitness function, thereby the mistake that under the prerequisite that keeps the program original function, exists in the repair procedure, a kind of software restorative procedure based on genetic algorithm, it may further comprise the steps
A. be the abstract syntax tree construction with program representation to be repaired, and generation 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 correct test case of carrying out in program, described negative testing use-case stops or draws the test case of error result for the program execute exception, and original program carried out positive test case, generate invariant in the described program by the invariant Core Generator;
B. the replicating original program obtains M copies of programs, and M individuality carried out mutation operation, and original program and a described M copies of programs are as the initial population in the genetic algorithm; The maximum evolutionary generation that setting program is evolved;
C. determine fitness function, described invariant as the invariant constraint of calculating fitness, to each individual all test case of carrying out, is calculated test case number and the invariant constraint passed through and keeps number, by calculating each individual fitness value;
D. genetic manipulation:
Each is comprised for the individual genetic manipulation that carries out in the population: variation, intersection and selection; It comprises, individuality in the population is carried out mutation operation and interlace operation, calculates fitness individual in the described population according to the method for step C then, selects M individuality to obtain population of future generation;
E. end condition is judged:
According to M individual fitness value in the population of new generation, be 1 if individual fitness value is arranged, namely by all test cases, and kept whole invariant constraints, the reparation that then hits pay dirk stops calculating;
Judge whether to reach maximum evolutionary generation, if reach, stop calculating;
Otherwise, repeat the D-E step.
On the basis of technique scheme, executable state or control flow structure in the corresponding program of each node of described abstract syntax tree.
On the basis of technique scheme, the corresponding ordered pair table<s of each state node of described abstract syntax tree, w s, the sequence number of s dactylus point, w sThe weights that refer to this node correspondence, and each node in the abstract syntax tree arranged weights, its weights arrange according to being:
If have only positive test case to have access to weight w s=1.0;
If have only the negative testing use-case to have access to weight w s=0.0;
If positive and negative test case all has access to weight w s=v p/ (v p+ v n);
V wherein pRepresent the number of times that this node is had access to by positive test case, v nRepresent the number of times that this node is had access to by the negative testing use-case.
On the basis of technique scheme, program is the service routine code when calculating fitness, the invariant constraint number of the test case number that executive routine calculating is passed through and maintenance.
On the basis of technique scheme, described fitness function is made up of two parts: at first calculate the ratio that the individual test case number of passing through accounts for all test cases, the more many fitness values of the test case of passing through are more big; In addition, calculate the number that individual invariant constraint keeps, fitness function is:
f ( x i ) = | { t ∈ T | ( x i ) Pass ( t ) } | | T | - | c p - c i | | c p |
Wherein, f (x i) represent individual x iFitness;
T represents test use cases, and t refers to test case wherein;
(x i) Pass (t) represents individual x iBy test case t, | T| represents the number of test case;
c pRepresent the invariant constraint number of original individuality when carrying out positive test case;
c iThe individual x of expression expression iWhen carrying out positive test case and c pConsistent invariant constraint number.
On the basis of technique scheme, described variation comprises and acts on that the negative testing use-case has access to and on the node in the path that positive test case does not have access to, according to the individuality of variation probability to choosing, the node minimum to its weights carries out mutation operation, mutation operation comprises the deletion to this node, insert new node or exchange with it with new node, and described new node is taken from other node in the individuality.
On the basis of technique scheme, described intersection comprises by two point of crossing of random algorithm generation, exchanges the node between two point of crossing.
On the basis of technique scheme, described intersection comprises two cross methods, and described two cross methods comprise that each individuality will intersect with original individuality and each individual optional other individuality intersects.
On the basis of technique scheme, described selection comprises that the individuality after intersecting is carried out fitness to be calculated, and selects high M individuality and the original individuality of fitness value to enter the next generation.
Because the principle of locality of program, program can obtain from other nodes of locations combinations of program in the wrong processing mode of certain position.The present invention has utilized uncertainty search and the convergence of genetic algorithm of genetic algorithm, genetic algorithm is used for the reparation of software fault.This method has significantly reduced developer's the workload in software is repaired, be a kind of effectively, software restorative procedure that automaticity is high.
Description of drawings
Fig. 1 is the process flow diagram based on the software restorative procedure of genetic algorithm that the present invention proposes.
Embodiment
As follows with reference to Fig. 1 implementation step of the present invention:
(1) program representation: be the abstract syntax tree construction with program representation, each node is an executable statement or one section control flow structure in the wherein said abstract syntax tree.The operation of evolving is positioned on the node of error checking use-case execution route.
Choose one group of test use cases T, make its all functions of energy test procedure 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 correct test case of carrying out in program, and described negative testing use-case stops or draw the test case of error result for the program execute exception.
By the invariant Core Generator, program is carried out positive test case, the invariant in the generator program uses when the invariant that generates is constrained in the calculating fitness value as invariant.
(2) initialization: evolutionary generation counter t=0 is set, maximum evolutionary generation MAX, the replicating original program obtains M copies of programs, and M individuality carried out mutation operation, and original program and a described M copy are as initial population.Described mutation operation comprises deletion, interpolation or the exchange to node.
(3) fitness calculates: determine fitness function, the quality of fitness function has determined evolution result's quality.Described fitness function is made up of two parts: at first calculate the individual test case number of passing through; Then, calculate the number that individual invariant constraint keeps.
Fitness function is:
f ( x i ) = | { t ∈ T | ( x i ) Pass ( t ) } | | T | - | c p - c i | | c p |
Wherein, f (x i) represent individual x iFitness;
T represents test use cases, and t refers to test case wherein;
(x i) Pass (t) represents individual x iBy test case t, | T| represents the number of test case;
c pRepresent the invariant constraint number of original individuality when carrying out positive test case;
c iThe individual x of expression expression iWhen carrying out positive test case and c pConsistent invariant constraint number.
(4) variation: overall situation variation probability is p m, according to the variation probability node that weights are lower in the individuality of choosing is carried out mutation operation, select at random it is deleted, adds new node or selects corresponding node and its exchange.Described new node is taken from other node of abstract syntax tree.
(5) intersect: crossover probability is 1.0, and in per generation, the individuality of each existence will carry out interlace operation, adopts two point to intersect, and namely the node between two point of crossing is exchanged, and the selection of described point of crossing is adopted at random and generated.Two kinds of different forms are adopted in interlace operation:
Each individuality always intersects with original individuality earlier;
Each individual optional other individuality intersects with it.
(6) select: the fitness value of the individuality that obtains after calculating intersects according to method described in (3), select higher M individuality and the original individuality of fitness value, obtain population of future generation;
(7) condition judgment: according to M individual fitness value in the population of new generation, judge whether that at first individual fitness value is 1, if having, namely by all test cases, and kept whole invariant constraints, the reparation that then hits pay dirk stops calculating; Otherwise, judge whether to reach maximum evolutionary generation, if reach, stop calculating, obtained finishing the program that part is repaired this moment; Otherwise repeating step (4) is to (7).
For a person skilled in the art, can make other various corresponding changes and distortion according to technical scheme described above and design, and these all changes and distortion should belong within the protection domain of claim of the present invention all.

Claims (9)

1. software restorative procedure based on genetic algorithm, it is characterized in that: it may further comprise the steps,
A. be the abstract syntax tree construction with program representation to be repaired, and generation 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 correct test case of carrying out in program, described negative testing use-case stops or draws the test case of error result for the program execute exception, and original program carried out positive test case, generate invariant in the described program by the invariant Core Generator;
B. the replicating original program obtains M copies of programs, and M individuality carried out mutation operation, and original program and a described M copies of programs are as the initial population in the genetic algorithm; The maximum evolutionary generation that setting program is evolved;
C. determine fitness function, described invariant as the invariant constraint of calculating fitness, to each individual all test case of carrying out, is calculated test case number and the invariant constraint passed through and keeps number, by calculating each individual fitness value;
D. genetic manipulation:
Each is comprised for the individual genetic manipulation that carries out in the population: variation, intersection and selection; It comprises, individuality in the population is carried out mutation operation and interlace operation, calculates fitness individual in the described population according to the method for step C then, selects M individuality to obtain population of future generation;
E. end condition is judged:
According to M individual fitness value in the population of new generation, be 1 if individual fitness value is arranged, namely by all test cases, and kept whole invariant constraints, the reparation that then hits pay dirk stops calculating;
Judge whether to reach maximum evolutionary generation, if reach, stop calculating;
Otherwise, repeat the D-E step.
2. a kind of software restorative procedure based on genetic algorithm according to claim 1 is characterized in that: executable state or control flow structure in the corresponding program of each node of described abstract syntax tree.
3. a kind of software restorative procedure based on genetic algorithm according to claim 1 is characterized in that:
The corresponding ordered pair table<s of each state node of described abstract syntax tree, w s, the sequence number of s dactylus point, w sThe weights that refer to this node correspondence, and each node in the abstract syntax tree arranged weights, its weights arrange according to being:
If have only positive test case to have access to weight w s=1.0;
If have only the negative testing use-case to have access to weight w s=0.0;
If positive and negative test case all has access to weight w s=v p/ (v p+ v n);
V wherein pRepresent the number of times that this node is had access to by positive test case, v nRepresent the number of times that this node is had access to by the negative testing use-case.
4. a kind of software restorative procedure based on genetic algorithm according to claim 1 is characterized in that: program is the service routine code when calculating fitness, and executive routine calculates the test case number that passes through and the invariant constraint number of maintenance.
5. a kind of software restorative procedure of calculating based on heredity according to claim 1, it is characterized in that: described fitness function is made up of two parts: at first calculate the ratio that the individual test case number of passing through accounts for all test cases, the more many fitness values of the test case of passing through are more big; In addition, calculate the number that individual invariant constraint keeps, fitness function is:
f ( x i ) = | { t ∈ T | ( x i ) Pass ( t ) } | | T | - | c p - c i | | c p |
Wherein, f (x i) represent individual x iFitness;
T represents test use cases, and t refers to test case wherein;
(x i) Pass (t) represents individual x iBy test case t, | T| represents the number of test case;
c pRepresent the invariant constraint number of original individuality when carrying out positive test case;
c iThe individual x of expression expression iWhen carrying out positive test case and c pConsistent invariant constraint number.
6. a kind of software restorative procedure based on genetic algorithm according to claim 1, it is characterized in that: described variation comprises and acts on that the negative testing use-case has access to and on the node in the path that positive test case does not have access to, according to the individuality of variation probability to choosing, the node minimum to its weights carries out mutation operation, mutation operation comprises the deletion to this node, insert new node or exchange with it with new node, and described new node is taken from other node in the individuality.
7. a kind of software restorative procedure based on genetic algorithm according to claim 1 is characterized in that: described intersection comprises by random algorithm and generates two point of crossing, exchanges the node between two point of crossing.
8. a kind of software restorative procedure based on genetic algorithm according to claim 7, it is characterized in that: described intersection comprises two cross methods, described two cross methods comprise that each individuality will intersect with original individuality and each individual optional other individuality intersects.
9. a kind of software restorative procedure based on genetic algorithm according to claim 1 is characterized in that: described selection comprises that the individuality after intersecting is carried out fitness to be calculated, and selects high M individuality and the original individuality of fitness value to enter the next generation.
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 true CN103294595A (en) 2013-09-11
CN103294595B 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)

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106886467A (en) * 2017-02-24 2017-06-23 电子科技大学 Method for optimizing is tested in multitask based on the comprehensive multi-target evolution of packet
CN108897688A (en) * 2018-06-29 2018-11-27 西安电子科技大学 Method for test examples design based on BWDSP processor
CN110750449A (en) * 2019-09-19 2020-02-04 中山大学 Test-driven webpage component function extraction method
CN111444079A (en) * 2019-01-16 2020-07-24 河南工业大学 Software defect repairing method and device
CN111737120A (en) * 2020-06-15 2020-10-02 河南工业大学 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
WO2023103574A1 (en) * 2021-12-10 2023-06-15 深圳前海微众银行股份有限公司 Unit test method and apparatus, electronic device, storage medium, and program

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

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106886467A (en) * 2017-02-24 2017-06-23 电子科技大学 Method for optimizing is tested in multitask based on the comprehensive multi-target evolution of packet
CN108897688A (en) * 2018-06-29 2018-11-27 西安电子科技大学 Method for test examples design based on BWDSP processor
CN111444079A (en) * 2019-01-16 2020-07-24 河南工业大学 Software defect repairing method and device
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
CN111737120A (en) * 2020-06-15 2020-10-02 河南工业大学 Software defect repairing method and device
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
WO2023103574A1 (en) * 2021-12-10 2023-06-15 深圳前海微众银行股份有限公司 Unit test method and apparatus, electronic device, storage medium, and program

Also Published As

Publication number Publication date
CN103294595B (en) 2016-06-22

Similar Documents

Publication Publication Date Title
CN103294595A (en) Genetic algorithm based software repair method
Wang et al. Search, align, and repair: data-driven feedback generation for introductory programming exercises
Wardat et al. Deeplocalize: Fault localization for deep neural networks
Nguyen et al. Recurring bug fixes in object-oriented programs
Cai et al. Design rule spaces: A new model for representing and analyzing software architecture
Gu et al. Muffin: Testing deep learning libraries via neural architecture fuzzing
KR102160780B1 (en) Bug fixing system and bug fixing method
García de la Barrera et al. Quantum software testing: State of the art
Castelein et al. Search-based test data generation for SQL queries
Courtieu et al. Certified universal gathering in for oblivious mobile robots
CN102799960B (en) The concurrent service flow process method for detecting abnormality of data-orlented model
Wu et al. Ggf: A graph-based method for programming language syntax error correction
Letsholo et al. TRAM: A tool for transforming textual requirements into analysis models
CN111782532A (en) Software fault positioning method and system based on network abnormal node analysis
CN101894073B (en) Defect automatic positioning device based on control flow intersection and automatic positioning method thereof
Liu Testing-based formal verification for theorems and its application in software specification verification
Malhotra et al. A new metric for predicting software change using gene expression programming
CN110297765B (en) Early evaluation method for software reliability
Valueian et al. Constructing automated test oracle for low observable software
Zojaji et al. Automated program repair using genetic programming and model checking
Liu Validating formal specifications using testing-based specification animation
Li et al. Reliability assurance for deep neural network architectures against numerical defects
Zhang et al. Regression test generation approach based on tree-structured analysis
Wang et al. Data-driven feedback generation for introductory programming exercises
Zakonov et al. GA-based and design by contract approach to test generation for EFSMs

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