Skip to content

Commit

Permalink
Merge 98df75f into 3242c21
Browse files Browse the repository at this point in the history
  • Loading branch information
DehengYang committed Feb 20, 2019
2 parents 3242c21 + 98df75f commit ece8094
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 3 deletions.
9 changes: 7 additions & 2 deletions .travis.yml
Expand Up @@ -4,13 +4,18 @@ matrix:
include:
- os: osx
- os: linux
jdk: oraclejdk7
jdk: openjdk7
- os: linux
jdk: oraclejdk8

sudo: true

install: "./.travis_install.sh"
#- mvn -X
install:
- mvn dependency:get -DrepoUrl=http://download.java.net/maven/2/ -Dartifact=org.eclipse.tycho:org.eclipse.jdt.core:3.12.0.v20160516-2131
- mkdir -p $HOME/.m2/repository/org/eclipse/jdt/
- cp -rf $HOME/.m2/repository/org/eclipse/tycho/* $HOME/.m2/repository/org/eclipse/jdt/
- "./.travis_install.sh"
script: "./.travis_run_tests.sh"

cache:
Expand Down
5 changes: 5 additions & 0 deletions .travis_install.sh
Expand Up @@ -4,6 +4,11 @@ cd "test-projects"
mvn clean package -DskipTests

cd ..
# git clone -b compat-java7 https://github.com/SpoonLabs/CoCoSpoon.git
# cd CoCoSpoon
# mvn clean install -DskipTests
# cp -rf ~/.m2/org/eclipse/tycho/* ~/.m2/org/eclipse/jdt/

git clone https://github.com/SpoonLabs/CoCoSpoon.git
cd CoCoSpoon
git checkout -b 975b9b07e04fc8a689f4b4ca2746ccb49b4c380e 975b9b07e04fc8a689f4b4ca2746ccb49b4c380e
Expand Down
2 changes: 1 addition & 1 deletion nopol/src/main/resources/config.ini
@@ -1,6 +1,6 @@
[general]
complianceLevel=7
timeoutTestExecution=5
timeoutTestExecution=200

[synth]
depth=3
Expand Down
@@ -0,0 +1,74 @@
package fr.inria.lille.localization;

import fr.inria.lille.localization.metric.Ochiai;
import fr.inria.lille.repair.common.config.NopolContext;
import fr.inria.lille.repair.nopol.SourceLocation;
import org.junit.Assert;
import org.junit.Test;

import java.io.FileInputStream;
import java.io.File;
import java.net.URL;
import java.util.List;
import java.util.Map;

import java.util.*; //added by deheng
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import java.util.Properties;

import static gov.nasa.jpf.util.test.TestJPF.assertEquals;
import static gov.nasa.jpf.util.test.TestJPF.assertTrue;

/**
* Modified by deheng on Feb 1, 2019.
* This test aims to expose the java.lang.RuntimeException when running test cases in Math_58, a real bug from defects4j. But this test file (CocospoonLocalizerTest.java) is created based on the version of Nopol of March 2017.
* Use `mvn clean package -DskipTests` to build nopol and use `mvn test -Dtest=CocospoonLocalizerTest` to run this test.
*/

// But this java.lang.RuntimeException seems to only happen when the Nopol and CoCospoon are built/installed in JDK 1.7. When Nopol and CoCoSpoon are built/installed in JDK 1.8, this test will pass.
public class CocospoonLocalizer2Test {

@Test
public void testOchiaiCoCoSpoonLocalizer() throws Exception {
String bug_id="Math58";
String mvn_option="";
if(!new File(bug_id).exists()){
String command = "mkdir " + bug_id +";\n cd " + bug_id + ";\n git init;\n git fetch https://github.com/Spirals-Team/defects4j-repair " + bug_id + ":" + bug_id + ";\n git checkout "+bug_id+";\n mvn -q test -DskipTests "+mvn_option+";\n mvn -q dependency:build-classpath -Dmdep.outputFile=cp.txt";
//String command = "mkdir ../Math58 && cd ../Math58 && defects4j checkout -p Math -v 58b -w . && cd ../nopol"; // Travis does not support `defects4j` command.
System.out.println("The command is:"+command);
Process p = Runtime.getRuntime().exec(new String[]{"sh", "-c", command});
p.waitFor();
if (p.exitValue() != 0) {
System.out.println("defects4j download Math_58 failed.");
}
}
/*Process p2 = Runtime.getRuntime().exec(new String[]{"sh", "-c", "cd ../Math_58 && defects4j test && cd ../nopol"});
p2.waitFor();
if (p2.exitValue() != 0) {
System.out.println("defects4j test Math_58 failed.");
}*/
File[] sources = new File[]{new File("Math58/src/main/java")}; // This is the source file of Math_58
String tests="org.apache.commons.math.distribution.HypergeometricDistributionTest,org.apache.commons.math.optimization.fitting.GaussianFitterTest"; // The first test case(Hyper...) is the specified test that can expose the problem of cocospoon (RuntimeException).
URL[] classpath = new URL[]{
new File("Math58/target/classes/").toURI().toURL(),
new File("Math58/target/test-classes/").toURI().toURL()
}; // This corresponds to the paths of java classes files.
String[] testClasses = tests.split(",");
CocoSpoonBasedSpectrumBasedFaultLocalizer localizer = new CocoSpoonBasedSpectrumBasedFaultLocalizer(new NopolContext(sources, classpath, testClasses), new Ochiai());
Map<SourceLocation, List<TestResult>> executedSourceLocationPerTest = localizer.getTestListPerStatement();

for(SourceLocation location : executedSourceLocationPerTest.keySet()){
System.out.println(location);
}

assertTrue(executedSourceLocationPerTest.size()>0); //If the runtimeException does not occur when running the specified test case, it means this test pass.

//SourceLocation sourceLocation1 = new SourceLocation("org.apache.commons.math.optimization.general.LevenbergMarquardtOptimizer", 741);
//System.out.println("dale stmt 0:"+executedSourceLocationPerTest.size()+" "+new ArrayList<>(executedSourceLocationPerTest.keySet()).get(0) +new ArrayList<>(executedSourceLocationPerTest.keySet()).get(0).getSuspiciousValue() );
//assertTrue(executedSourceLocationPerTest.keySet().contains(sourceLocation1));
//List<SourceLocation> sortedStatements = new ArrayList<>(executedSourceLocationPerTest.keySet());
//assertEquals(1, sortedStatements.get(0).getSuspiciousValue(), 10E-3);
}

}

0 comments on commit ece8094

Please sign in to comment.