Skip to content

give-to/Hercules

Repository files navigation

Hercules

This repository is used to replicate the experiments of article "Detecting, Creating, Repairing, and Understanding Indivisible Multi-Hunk Bugs" on Hercules.

"Harnessing Evolution for Multi-Hunk Program Repair" proposes Hercules. Since the source code is not provided by the authors, we implement Hercules in this repository according to the description in the paper.

1. Modification

We only reproduced the Hercules-MinusHistory.

1.1 Spectrum Based Fault Localization

We use the GZoltar to identify potential repair locations. The formula we used in GZoltar is Ochiai.

1.2 Identification of Evolutionary Siblings

① We use soot to extract program context.

② When comparing two AST nodes N1 and N2, we only use kind compatibility and name similarity. Because there are some nodes, the JDT cannot get their type.

1.3 Patch Generation

We completed the stages of building an abstract syntax tree and generating patches based on TBar.

① We change the a field isTestFixPatterns in edu.lu.uni.serval.tbar.AbstractFixer from false to true, so that it can generate more plausible patches.

② We removed some templates and kept only the templates used in PAR, ACS, Elixir, which are cited by the authors in the Implementation part.

③ We transform the patches generated by TBar according to this rule.

1.4 Ranking of Candidate Patches

We use ODS to rank the candidate patches, which is also a learning-based ranking model. Because we do not have the ranking model similar to Elixir.

2. Environment

3. Experiment Setup

  • Timeout: 5h

4. Excluded Bug

None

5. Installation

5.1 Create the docker image

Use the Dockerfile in ./Docker to create the docker image.

docker build -t hercules-env .

This docker image includes Defects4J, CatenaD4J, JDK 1.8, and Python 3.8.

5.2 Create the container with this image

docker run -it --name hercules hercules-env /bin/bash

5.3 Clone the Hercules repository

At the root of this container, we clone the Hercules repository.

cd /
git clone https://github.com/give-to/Hercules.git
cd /Hercules && chmod +x *

5.4 Install Dependencies

After testing, we found that using pip in the Docker file might cause image creation to fail, so configuration inside the container is required.

# Preparing the environment
pip install -r requirements.txt

6. Quick Test

It takes several minutes to quickly test your installation. (Note: In quick test, the ochiai.ranking.txt in Chart_18_2 only contains one location! )

cp location/105SampleBugsResult/Chart_18_2/short.txt location/105SampleBugsResult/Chart_18_2/ochiai.ranking.txt
# Test your environment
./run.sh /CatenaD4JProjects /CatenaD4J ./location/105SampleBugsResult ./test.txt

After finishing the repair, the results are in folders: patches and results.

  • patches: The generated patches. Its structure is as follows:
 patches
 |--- Chart_2_5               :  bugid
 |------ group_1              :  the first siblings
 |--------- 0.txt             :  specific patches, each row is a partial patch
 |------ group_2              :  the second siblings
 |--------- 0.txt             :  specific patches, each row is a partial patch
  • results: The validation results. The plausible patch will show Pass.

7. Experiment Reproduction

It may take about 22 days to finish the entire experiment. You can also modify 105_bugs_list.txt to determine the bugs to be fixed.

cp location/105SampleBugsResult/Chart_18_2/backup.txt location/105SampleBugsResult/Chart_18_2/ochiai.ranking.txt
rm -rf patches/ results/
# Run the whole experiment
./run.sh /CatenaD4JProjects /CatenaD4J ./location/105SampleBugsResult ./105_bugs_list.txt

After finishing the repair, the results are in folders: patches and results.

8. Usage

8.1 Repair Bugs

In the Hercules directory:

./run.sh <ProjectsRoot> <CatenaD4JHome> <FLroot> <bugListFile>

Where:

  • ProjectsRoot: the root directory that you want to checkout all CatenaD4J bugs in.
  • CatenaD4JHome: the root directory of CatenaD4J.
  • FLroot: the root directory of ochiai results of all bugs.
  • bugListFile: a file contains all the bugs to be fixed.

8.2 Find Siblings and Generate Patches

The Hercules-1.0-SNAPSHOT-jar-with-dependencies.jar in the root directory contains 3 parts, finding siblings, patch generation and patch ranking. It saves all patches and patch ranking results in patches directory. It accepts 4 parameters:

java -cp Hercules-1.0-SNAPSHOT-jar-with-dependencies.jar org.example.hercules.Main_NFL <ProjectsRoot> <CatenaD4JHome> <FLroot> <bugListFile>

Where:

  • ProjectsRoot: the all buggy projects' root directory.
ProjectRootDir
| Chart_1_1
|	| 
|	|
| Chart_1_2
|	|
|	|
  • CatenaD4JHome: the root directory of CatenaD4J.
  • FLRoot: the root directory of fault localization results. (The file name of fault localization results must be ochiai.ranking.txt.)
FLRoot
| Chart_1_1
|	| ochiai.ranking.txt
| Chart_1_2
|	| ochiai.ranking.txt
  • bugListFile: A file contains all projectsId that you want to repair.

Example:

# You should have checked out the bugs first.
java -cp Hercules-1.0-SNAPSHOT-jar-with-dependencies.jar /CatenaD4JProjects CatenaD4J ./location/105SampleBugsResult ./105_bugs_list.txt

8.3 Validation

The hercules_valid_v2.py will validate patches under patches directory according to patch ranking results, until all patches have been validated or timed out. The patch that shows Pass is the plausible patch. It accepts 1 parameter:

python3 hercules_valid_v2.py <ProjectsRoot>
  • ProjectsRoot: the all buggy projects' root directory.

Example:

# You should have checked out the bugs and generated the patches first.
python3 hercules_valid_v2.py /CatenaD4JProjects

9. Structure of the Directories

|--- README.md               :  User guidance
|--- C4J_results             :  Patches and results of CatenaD4J bugs
|--- Docker                  :  Dockerfile
|--- location                :  Bug positions localized with GZoltar of CatenaD4J bugs
|--- scripts                 :  Apply patches to projects
|--- src                     :  Source code

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published