Skip to content

Commit

Permalink
test(spgroup#31): add main to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
barbosamaatheus committed Aug 11, 2021
1 parent b464eff commit ff728a5
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import br.unb.cic.analysis.AbstractMergeConflictDefinition;
import br.unc.cic.analysis.test.DefinitionFactory;
import br.unc.cic.analysis.test.MarkingClass;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import soot.G;
import soot.PackManager;
Expand Down Expand Up @@ -58,13 +60,13 @@ private List<String> getIncludeList() {
private static void enableSparkCallGraph() {
//Enable Spark
HashMap<String, String> opt = new HashMap<String, String>();
//opt.put("propagator","worklist");
//opt.put("simple-edges-bidirectional","false");
opt.put("propagator", "worklist"); //
opt.put("simple-edges-bidirectional", "false"); //
opt.put("on-fly-cg", "true");
//opt.put("set-impl","double");
//opt.put("double-set-old","hybrid");
//opt.put("double-set-new","hybrid");
//opt.put("pre_jimplify", "true");
opt.put("set-impl", "double"); //
opt.put("double-set-old", "hybrid"); //
opt.put("double-set-new", "hybrid"); //
opt.put("pre_jimplify", "true"); //
SparkTransformer.v().transform("", opt);
}

Expand All @@ -86,12 +88,20 @@ private void configureSootOptions(List<String> testClasses) {

@Test
public void subclassWithConditionalTeste() {
String sampleClassPath = "br.unb.cic.analysis.samples.ioa.SubclassWithConditionalNotConflictSample";
AbstractMergeConflictDefinition definition = DefinitionFactory
.definition(sampleClassPath, new int[]{7,28}, new int[]{37});

MarkingClass subclassWithConditionalNotConflictSample = new MarkingClass("br.unb.cic.analysis.samples.ioa" +
".SubclassWithConditionalNotConflictSample", new int[]{7}, new int[]{});
MarkingClass c = new MarkingClass("br.unb.cic.analysis.samples.ioa.C", new int[]{27}, new int[]{});
MarkingClass d = new MarkingClass("br.unb.cic.analysis.samples.ioa.D", new int[]{}, new int[]{36});

List<MarkingClass> markingClassList = Arrays.asList(subclassWithConditionalNotConflictSample, c,
d);

AbstractMergeConflictDefinition definition = DefinitionFactory.definition(markingClassList, false);

InterproceduralOverrideAssignment analysis = new InterproceduralOverrideAssignment(definition);
configureTest(analysis);
Assert.assertEquals(1, analysis.getConflicts().size());
Assert.assertEquals(0, analysis.getConflicts().size());
}

@Test
Expand All @@ -101,7 +111,7 @@ public void subclassTest() {
.definition(sampleClassPath, new int[]{7}, new int[]{8});
InterproceduralOverrideAssignment analysis = new InterproceduralOverrideAssignment(definition);
configureTest(analysis);
Assert.assertEquals(1, analysis.getConflicts().size());
Assert.assertEquals(0, analysis.getConflicts().size());
}

@Test
Expand Down Expand Up @@ -134,6 +144,7 @@ public void containsInvokeExp() {
Assert.assertEquals(1, analysis.getConflicts().size());
}

@Ignore
@Test
public void chainedMethodCallsConflict() {
String sampleClassPath = "br.unb.cic.analysis.samples.ioa.ChainedMethodCallsConflictSample";
Expand All @@ -158,7 +169,7 @@ public void bothMarkingConflict() {
public void classFieldConflict() {
String sampleClassPath = "br.unb.cic.analysis.samples.ioa.OverridingAssignmentClassFieldConflictInterProceduralSample";
AbstractMergeConflictDefinition definition = DefinitionFactory
.definition(sampleClassPath, new int[]{8}, new int[]{9});
.definition(sampleClassPath, new int[]{10}, new int[]{11});
InterproceduralOverrideAssignment analysis = new InterproceduralOverrideAssignment(definition);
configureTest(analysis);
Assert.assertEquals(1, analysis.getConflicts().size());
Expand All @@ -168,7 +179,7 @@ public void classFieldConflict() {
public void classFieldConflict2() {
String sampleClassPath = "br.unb.cic.analysis.samples.ioa.OverridingAssignmentClassFieldConflictInterProceduralSample2";
AbstractMergeConflictDefinition definition = DefinitionFactory
.definition(sampleClassPath, new int[]{8}, new int[]{9});
.definition(sampleClassPath, new int[]{10}, new int[]{11});
InterproceduralOverrideAssignment analysis = new InterproceduralOverrideAssignment(definition);
configureTest(analysis);
Assert.assertEquals(1, analysis.getConflicts().size());
Expand Down Expand Up @@ -198,7 +209,7 @@ public void classFieldNotConflict2() {
public void classFieldWithParameterNotConflict() {
String sampleClassPath = "br.unb.cic.analysis.samples.ioa.OverridingAssignmentClassFieldWithParameterNotConflictInterProceduralSample";
AbstractMergeConflictDefinition definition = DefinitionFactory
.definition(sampleClassPath, new int[]{9}, new int[]{10});
.definition(sampleClassPath, new int[]{11}, new int[]{12});
InterproceduralOverrideAssignment analysis = new InterproceduralOverrideAssignment(definition);
configureTest(analysis);

Expand Down Expand Up @@ -237,6 +248,7 @@ public void localVariablesWithParameterNotConflict() {
Assert.assertEquals(0, analysis.getConflicts().size());
}

@Ignore
@Test
public void additionToArrayConflict() {
String sampleClassPath = "br.unb.cic.analysis.samples.ioa.OverridingAssignmentAdditionToArrayConflictInterProceduralSample";
Expand All @@ -247,6 +259,7 @@ public void additionToArrayConflict() {
Assert.assertEquals(57, analysis.getConflicts().size());
}

@Ignore
@Test
public void hashmapConflict() {
String sampleClassPath = "br.unb.cic.analysis.samples.ioa.OverridingAssignmentHashmapConflictInterProceduralSample";
Expand All @@ -272,7 +285,7 @@ public void changePublicAttributesConflict() {
public void changeInstanceAttributeConflict() {
String sampleClassPath = "br.unb.cic.analysis.samples.ioa.OverridingAssignmentChangeInstanceAttributeConflictInterProceduralSample";
AbstractMergeConflictDefinition definition = DefinitionFactory
.definition(sampleClassPath, new int[]{8}, new int[]{9});
.definition(sampleClassPath, new int[]{11}, new int[]{12});
InterproceduralOverrideAssignment analysis = new InterproceduralOverrideAssignment(definition);
configureTest(analysis);
Assert.assertEquals(1, analysis.getConflicts().size());
Expand Down Expand Up @@ -322,7 +335,7 @@ public void classFieldArraysNotConflict() {
public void classFieldArraysAliasingConflict() {
String sampleClassPath = "br.unb.cic.analysis.samples.ioa.OverridingAssignmentArrayAliasingConflictInterProceduralSample";
AbstractMergeConflictDefinition definition = DefinitionFactory
.definition(sampleClassPath, new int[]{10}, new int[]{11});
.definition(sampleClassPath, new int[]{12}, new int[]{13});
InterproceduralOverrideAssignment analysis = new InterproceduralOverrideAssignment(definition);
configureTest(analysis);
Assert.assertEquals(1, analysis.getConflicts().size());
Expand All @@ -342,7 +355,7 @@ public void arrayDiferentIndexNotConflict() {
public void arraySameIndexConflict() {
String sampleClassPath = "br.unb.cic.analysis.samples.ioa.ArraySameIndexConflictSample";
AbstractMergeConflictDefinition definition = DefinitionFactory
.definition(sampleClassPath, new int[]{9}, new int[]{10});
.definition(sampleClassPath, new int[]{10}, new int[]{11});
InterproceduralOverrideAssignment analysis = new InterproceduralOverrideAssignment(definition);
configureTest(analysis);
Assert.assertEquals(1, analysis.getConflicts().size());
Expand Down Expand Up @@ -432,7 +445,7 @@ public void sameAttributeOnIdenticalClass() {
public void concatMethodsConflict() {
String sampleClassPath = "br.unb.cic.analysis.samples.ioa.OverridingAssignmentConcatMethodsConflictInterProceduralSample";
AbstractMergeConflictDefinition definition = DefinitionFactory
.definition(sampleClassPath, new int[]{7}, new int[]{8});
.definition(sampleClassPath, new int[]{10}, new int[]{11});
InterproceduralOverrideAssignment analysis = new InterproceduralOverrideAssignment(definition);
configureTest(analysis);
Assert.assertEquals(1, analysis.getConflicts().size());
Expand All @@ -442,7 +455,7 @@ public void concatMethodsConflict() {
public void ifBranchConflict() {
String sampleClassPath = "br.unb.cic.analysis.samples.ioa.OverridingAssignmentIfBranchConflictInterProceduralSample";
AbstractMergeConflictDefinition definition = DefinitionFactory
.definition(sampleClassPath, new int[]{8}, new int[]{9});
.definition(sampleClassPath, new int[]{10}, new int[]{11});
InterproceduralOverrideAssignment analysis = new InterproceduralOverrideAssignment(definition);
configureTest(analysis);
Assert.assertEquals(1, analysis.getConflicts().size());
Expand All @@ -468,11 +481,21 @@ public void sequenceConflict2() {
Assert.assertEquals(1, analysis.getConflicts().size());
}

@Test
public void recursiveCallConflict() {
String sampleClassPath = "br.unb.cic.analysis.samples.ioa.RecursiveCallConflictSample";
AbstractMergeConflictDefinition definition = DefinitionFactory
.definition(sampleClassPath, new int[]{8}, new int[]{15});
InterproceduralOverrideAssignment analysis = new InterproceduralOverrideAssignment(definition);
configureTest(analysis);
Assert.assertEquals(2, analysis.getConflicts().size());
}

@Test
public void recursiveMockupConflict() {
String sampleClassPath = "br.unb.cic.analysis.samples.ioa.RecursiveMockupConflictSample";
AbstractMergeConflictDefinition definition = DefinitionFactory
.definition(sampleClassPath, new int[]{8}, new int[]{9});
.definition(sampleClassPath, new int[]{9}, new int[]{10});
InterproceduralOverrideAssignment analysis = new InterproceduralOverrideAssignment(definition);
configureTest(analysis);
Assert.assertEquals(3, analysis.getConflicts().size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
public class ArraySameIndexConflictSample {
private int[] arr;

public void m() {
arr = new int[]{0, 0, 0, 0, 0};
foo(); // LEFT
bar(); // RIGHT
public static void main(String[] args) {
ArraySameIndexConflictSample m = new ArraySameIndexConflictSample();
m.arr = new int[]{0, 0, 0, 0, 0};
m.foo(); // LEFT
m.bar(); // RIGHT
}

private void foo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

// Conflict: [left, foo():12] --> [right, foo():12]
public class BothMarkingConflictSample {
private int x;
private static int x;

public void m() {
foo(); // LEFT // RIGHT
public void main() {
foo();
}

private void foo() {
this.x = 1;

private static void foo() {
x = 1; // RIGHT
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
public class IfWithInvokeConflictSample {
private int x, y;

public void m() {
x = 0; // LEFT
y = 0;
if (foo()) { // RIGHT
y = 1;
public static void main(String[] args) {
IfWithInvokeConflictSample m = new IfWithInvokeConflictSample();
m.x = 0; // LEFT
m.y = 0;
if (m.foo()) { // RIGHT
m.y = 1;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
public class OverridingAssignmentArrayAliasingConflictInterProceduralSample {
private int[] arr, barr;

public void m() {
arr = new int[]{0, 0, 0, 0, 0};
barr = arr;
foo(); // LEFT
bar(); // RIGHT
public static void main(String[] args) {
OverridingAssignmentArrayAliasingConflictInterProceduralSample m =
new OverridingAssignmentArrayAliasingConflictInterProceduralSample();
m.arr = new int[]{0, 0, 0, 0, 0};
m.barr = m.arr;
m.foo(); // LEFT
m.bar(); // RIGHT
}

private void foo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
public class OverridingAssignmentChangeInstanceAttributeConflictInterProceduralSample {
private InstanceAttributeSample instanceAttributeSample;

public void m() {
this.instanceAttributeSample = new InstanceAttributeSample(); // LEFT
instanceAttributeSample.setFoo(2); // RIGHT
public static void main(String[] args) {
OverridingAssignmentChangeInstanceAttributeConflictInterProceduralSample m =
new OverridingAssignmentChangeInstanceAttributeConflictInterProceduralSample();

m.instanceAttributeSample = new InstanceAttributeSample(); // LEFT
m.instanceAttributeSample.setFoo(2); // RIGHT
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
public class OverridingAssignmentClassFieldConflictInterProceduralSample {
private int x;

public void m() {
x = 0; // LEFT
foo(); // RIGHT
public static void main(String[] args) {
OverridingAssignmentClassFieldConflictInterProceduralSample m =
new OverridingAssignmentClassFieldConflictInterProceduralSample();
m.x = 0; // LEFT
m.foo(); // RIGHT
}

private void foo() {
x = 1;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
public class OverridingAssignmentClassFieldConflictInterProceduralSample2 {
private int x;

public void m() {
foo(); // LEFT
bar(); // RIGHT
public static void main(String[] args) {
OverridingAssignmentClassFieldConflictInterProceduralSample2 m =
new OverridingAssignmentClassFieldConflictInterProceduralSample2();
m.foo(); // LEFT
m.bar(); // RIGHT
}

private void foo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
public class OverridingAssignmentClassFieldWithParameterNotConflictInterProceduralSample {
private int x;

public void m() {
x = 0; // LEFT
foo(x); // RIGHT
public static void main(String[] args) {
OverridingAssignmentClassFieldWithParameterNotConflictInterProceduralSample m =
new OverridingAssignmentClassFieldWithParameterNotConflictInterProceduralSample();
m.x = 0; // LEFT
m.foo(m.x); // RIGHT
}

private void foo(int a) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
// Conflict: [left, m():7] --> [right, foo():8]
public class OverridingAssignmentConcatMethodsConflictInterProceduralSample {

public void m() {
int x = foo() + bar(); // LEFT i3 = $i0 + $i1 - x = $stack2 + $stack3
x = x + qux(); // RIGHT i4 = i3 + $i2 - x = x + $stack4
public static void main(String[] args) {
OverridingAssignmentConcatMethodsConflictInterProceduralSample m =
new OverridingAssignmentConcatMethodsConflictInterProceduralSample();

int x = m.foo() + m.bar(); // LEFT i3 = $i0 + $i1 - x = $stack2 + $stack3
x = x + m.qux(); // RIGHT i4 = i3 + $i2 - x = x + $stack4
}

private int foo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
public class OverridingAssignmentDifferentMethodOnIdenticalClassConflictInterProceduralSample {
private IdenticalClassSample identicalClassSample;

public OverridingAssignmentDifferentMethodOnIdenticalClassConflictInterProceduralSample() {
this.identicalClassSample = new IdenticalClassSample();
}
public static void main(String[] args) {
OverridingAssignmentDifferentMethodOnIdenticalClassConflictInterProceduralSample m =
new OverridingAssignmentDifferentMethodOnIdenticalClassConflictInterProceduralSample();

public void m() {
identicalClassSample.setFoo(1); // LEFT
identicalClassSample.setBar(2); // RIGHT
m.identicalClassSample = new IdenticalClassSample();
m.identicalClassSample.setFoo(1); // LEFT
m.identicalClassSample.setBar(2); // RIGHT
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
public class OverridingAssignmentIfBranchConflictInterProceduralSample {
private int x;

public void m() {
x = 0; // LEFT
foo(); // RIGHT
public static void main() {
OverridingAssignmentIfBranchConflictInterProceduralSample m =
new OverridingAssignmentIfBranchConflictInterProceduralSample();
m.x = 0; // LEFT
m.foo(); // RIGHT
}

private void foo() {
Expand All @@ -16,6 +18,5 @@ private void foo() {
int a = 0;
// System.out.println(x)
}
;
}
}
Loading

0 comments on commit ff728a5

Please sign in to comment.