In this project we have developed a tool written in Python which gets a buggy Javascript file with a set of tests as an input, and as the output it gives out the repaired program that can pass all the tests.
In a nutshell, a automated program repair tool is comprised of two different modules which must be executed sequencially.
At first we need to find the suspicious elements in the program and assign a suspiciousness value to each element. This stage is called fault localization. There are many ways for finding these suspicious elements. The technique that was used in this project is called Spectrum-Based Fault Localization (SBFL).
We used four different SBFL methods to calculate the suspiciousness values for program elements:
- Tarantula
- Ochiai
- Jaccard
- GenProg
After we calculated the suspiciousness values, now we iterate through all suspicious elements and apply a bug fix pattern according to the type of the element. We used the bug fix patterns discussed in Pan et al. paper (Except FOR_THB bug fix pattern which is a domain-specific fix pattern to repair the security vulnerablities that "this binding" can create in Javascript).
The current bug fix patterns that the tool supports are as below:
- IF_CC
- IF_APC
- IF_RMV
- TY_ATC
- MC_DAP
- SQ_RMO
- SQ_RFO
- FOR_THB
So overall repair algorithm used can be summarized in the pseudo-code below:
def program_repair():
for buggyCode in possibleBuggyCodes:
for pattern in getPatterns(buggyCode):
getRepairAlgorithm(pattern).run()
After cloning the project, you must install the required libraries. Since some of the repair patterns use the Z3 library for static analysis, make sure you install it properly at the project directory.
These are some examples for demonstrating how to use the tool:
Input:
python3 js-buxter.py -s 44 -fl ochiai
Output:
Patch:
IF_CC_Repair on "if (rr[i]>=stopIndex) ans *= (1 - pp[i])"
Repair Time: 1.4366938370000002 Seconds
Repaired program can be found in "./sample_code/repaired/sample_044_repaired.js"
Input:
js-buxter.py -s 0 -r IF_CC MC_DAP -d
Output:
TestCase #1: -- PASSED
Real Value: SCALENE
Predicted Value: SCALENE
Locations: [[0, 26], [27, 53], [54, 80], [82, 303], [110, 303], [116, 172], [177, 227], [232, 280], [285, 301], [305, 335]]
TestCase #2: -- FAILED
Real Value: ISOSCELES
Predicted Value: SCALENE
Locations: [[0, 26], [27, 53], [54, 80], [82, 303], [110, 303], [116, 172], [177, 227], [232, 280], [285, 301], [305, 335]]
TestCase #3: -- PASSED
Real Value: ISOSCELES
Predicted Value: ISOSCELES
Locations: [[0, 26], [27, 53], [54, 80], [82, 303], [110, 303], [116, 172], [177, 227], [232, 280], [262, 280], [305, 335]]
TestCase #4: -- FAILED
Real Value: ISOSCELES
Predicted Value: SCALENE
Locations: [[0, 26], [27, 53], [54, 80], [82, 303], [110, 303], [116, 172], [177, 227], [232, 280], [285, 301], [305, 335]]
TestCase #5: -- PASSED
Real Value: EQUILATERAL
Predicted Value: EQUILATERAL
Locations: [[0, 26], [27, 53], [54, 80], [82, 303], [110, 303], [116, 172], [177, 227], [207, 227], [305, 335]]
TestCase #6: -- PASSED
Real Value: INVALID
Predicted Value: INVALID
Locations: [[0, 26], [27, 53], [54, 80], [82, 303], [110, 303], [116, 172], [155, 172], [305, 335]]
#####
Code Element: (Suspiciousness: 0.8)
Location: [285, 301]
return 'SCALENE'
#####
#####
Code Element: (Suspiciousness: 0.6666666666666666)
Location: [232, 280]
if (a == b && b != c)
return 'ISOSCELES'
#####
...
IF_CC_Repair on "if (a == b && b != c)
return 'ISOSCELES'"
TestCase #1: -- PASSED
Real Value: SCALENE
Predicted Value: SCALENE
Locations: []
TestCase #2: -- PASSED
Real Value: ISOSCELES
Predicted Value: ISOSCELES
Locations: []
TestCase #3: -- PASSED
Real Value: ISOSCELES
Predicted Value: ISOSCELES
Locations: []
TestCase #4: -- PASSED
Real Value: ISOSCELES
Predicted Value: ISOSCELES
Locations: []
TestCase #5: -- PASSED
Real Value: EQUILATERAL
Predicted Value: EQUILATERAL
Locations: []
TestCase #6: -- PASSED
Real Value: INVALID
Predicted Value: INVALID
Locations: []
Repaired!
Patch:
IF_CC_Repair on "if (a == b && b != c)
return 'ISOSCELES'"
Repair Time: 3.2592488250000002 Seconds
Repaired program can be found in "./sample_code/repaired/sample_000_repaired.js"
Short Switch | Long Switch | Domain | Default | Required | Description |
---|---|---|---|---|---|
-s | --sample | [0, 49] | - | Yes | Choose the sample number from ./sample_code folder |
-h | --help | - | - | No | Get the options manual |
-fl | --fault_localization | ['tarantula', 'ochiai', 'jaccard', 'genprog'] | tarantula | No | Choose the fault localization method. You can choose only one. |
-r | --repair | ["FOR_THB", "MC_DAP", "SQ_RMO", "SQ_RFO", "IF_RMV", "TY_ATC", "IF_APC", "IF_CC"] | All | No | Choose the repair patterns that you want to be applied. You can choose multiple patterns. If none is selected, all of them will be taken into account |
-d | --debug | - | False | No | It will print out extra information about the repair (highly recommended to turn in on) |