-
Notifications
You must be signed in to change notification settings - Fork 34
Tuscan square detectors #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mmk-1
wants to merge
42
commits into
UT-SE-Research:master
Choose a base branch
from
mmk-1:tuscan_square_detectors
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
7488843
tuscan and alphabetical
d17683c
tuscan
8ed860a
detector factory
05c1213
fixed tuscan for 3 and 5
ba89c16
fixed tuscan for 3 and 5
9bf7466
fixed tuscan orders for 3 & 5
128a489
fixed typo
59f11bf
squashed commits
990ad2c
Merge branch 'master' of https://github.com/mmk-1/iDFlakies
mmk-1 c54ee57
fixed whitespaces
72a0e41
fixed Tuscan.java
bf1cc28
fixed alphabeticalDetector.java
b2a9236
fixed DetectorFactory.java
a29ea16
fixed whitespaces
9c305ec
fixed issues mentioned in PR review
259518c
TuscanIntraClass
9d726a3
update tuscanIntraClassOrder()
e8cff40
add test
2c3f205
update testshuffler
1193c73
update tuscan only class detector
a8e7b13
update tuscan
0a0d910
inter class
6553dcb
fixed round calculation in inter-class
6ce0959
removed unnecessary imports
2e5dc88
added tuscan inter class test
cb62cf8
added inter-class test
a489f2c
fixed tests
964d150
fixed onlyclass
9c505cd
fixed whitespaced
4087f5e
added alphabetical-class-method
1b40aea
fixed empty line
9a0dafd
reflected PR #48 changes
52d0aa8
Merge branch 'master' into tuscan_square_detectors
6e3a511
fixed assertion error
24e0e51
moved tuscan-inter-class to another branch
0db2f7d
Revert "fixed assertion error"
mmk-1 c635c0b
fixed tuscan assert error
dd81e59
fixed PR #49 commented issues
f2dade2
indentation
702a3fd
spacing
b558112
refactored tuscan tests
add6792
refactored another tuscan test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package edu.illinois.cs.dt.tools.detection.detectors; | ||
|
|
||
| import edu.illinois.cs.dt.tools.runner.InstrumentingSmartRunner; | ||
| import edu.illinois.cs.dt.tools.utility.Tuscan; | ||
| import edu.illinois.cs.testrunner.configuration.Configuration; | ||
|
|
||
| import java.io.File; | ||
|
|
@@ -24,10 +25,12 @@ public static Detector makeDetector(final InstrumentingSmartRunner runner, final | |
| return new OriginalDetector(runner, baseDir, rounds, tests); | ||
| } else if (detectorType().equals("smart-shuffle")) { | ||
| return new SmartShuffleDetector(runner, baseDir, rounds, tests, detectorType()); | ||
| } else if (detectorType().equals("tuscan")){ | ||
| return new TuscanOnlyClassDetector(runner, baseDir, rounds, detectorType(), tests); | ||
| } else if (detectorType().startsWith("alphabetical")) { | ||
| return new AlphabeticalDetector(runner, baseDir, rounds, detectorType(), tests); | ||
| } else if (detectorType().equals("tuscan")) { | ||
| return new TuscanOnlyClassDetector(runner, baseDir, rounds, detectorType(), tests); | ||
| } else if (detectorType().equals("tuscan-intra-class")) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe move this above to put next to tuscan (or move tuscan below to be next to this one). |
||
| return new TuscanIntraClassDetector(runner, baseDir, rounds, detectorType(), tests); | ||
| } | ||
| return new RandomDetector("random", baseDir, runner, rounds, tests); | ||
| } | ||
|
|
||
89 changes: 89 additions & 0 deletions
89
.../src/main/java/edu/illinois/cs/dt/tools/detection/detectors/TuscanIntraClassDetector.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| package edu.illinois.cs.dt.tools.detection.detectors; | ||
|
|
||
| import java.io.File; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
|
|
||
| import edu.illinois.cs.dt.tools.detection.DetectionRound; | ||
| import edu.illinois.cs.dt.tools.detection.DetectorUtil; | ||
| import edu.illinois.cs.dt.tools.detection.TestShuffler; | ||
| import edu.illinois.cs.dt.tools.detection.filters.ConfirmationFilter; | ||
| import edu.illinois.cs.dt.tools.detection.filters.UniqueFilter; | ||
| import edu.illinois.cs.dt.tools.runner.InstrumentingSmartRunner; | ||
| import edu.illinois.cs.testrunner.data.results.TestRunResult; | ||
| import edu.illinois.cs.testrunner.runner.Runner; | ||
|
|
||
| public class TuscanIntraClassDetector extends ExecutingDetector { | ||
| private final List<String> tests; | ||
| private TestRunResult origResult; | ||
|
|
||
| private final HashMap<String, List<String>> classToMethods; | ||
| private final TestShuffler testShuffler; | ||
|
|
||
| public static int getClassesSize(List<String> tests) { | ||
| List<String> classes = new ArrayList<String>(); | ||
| for (final String test : tests) { | ||
| final String className = TestShuffler.className(test); | ||
| if (!classes.contains(className)) { | ||
| classes.add(className); | ||
| } | ||
| } | ||
| return classes.size(); | ||
| } | ||
|
|
||
| public static int findMaxMethodSize(HashMap<String, List<String>> classToMethods) { | ||
| int maxMethodSize = 0; | ||
| for (String className : classToMethods.keySet()) { | ||
| int nn = classToMethods.get(className).size(); | ||
| if (maxMethodSize < nn) { | ||
| maxMethodSize = nn; | ||
| } | ||
| } | ||
| return maxMethodSize; | ||
| } | ||
|
|
||
| public TuscanIntraClassDetector(final Runner runner, final File baseDir, final int rounds, final String type, final List<String> tests) { | ||
| super(runner, baseDir, rounds, type); | ||
| classToMethods = new HashMap<>(); | ||
| for (final String test : tests) { | ||
| final String className = TestShuffler.className(test); | ||
| if (!classToMethods.containsKey(className)) { | ||
| classToMethods.put(className, new ArrayList<>()); | ||
| } | ||
| classToMethods.get(className).add(test); | ||
| } | ||
| int classSize = classToMethods.keySet().size(); | ||
| if (classSize == 3 || classSize == 5) { | ||
| classSize++; | ||
| } | ||
| int maxMethodSize = findMaxMethodSize(classToMethods); | ||
| if (maxMethodSize == 3 || maxMethodSize == 5) { | ||
| maxMethodSize++; | ||
| } | ||
| this.rounds = rounds; | ||
| if (classSize > maxMethodSize) { | ||
| if (this.rounds > classSize) { | ||
| this.rounds = classSize; | ||
| } | ||
| } else { | ||
| if (this.rounds > maxMethodSize) { | ||
| this.rounds = maxMethodSize; | ||
| } | ||
| } | ||
| this.tests = tests; | ||
| this.testShuffler = new TestShuffler(type, rounds, tests, baseDir); | ||
| this.origResult = DetectorUtil.originalResults(tests, runner); | ||
| if (runner instanceof InstrumentingSmartRunner) { | ||
| addFilter(new ConfirmationFilter(name, tests, (InstrumentingSmartRunner) runner)); | ||
| } else { | ||
| addFilter(new ConfirmationFilter(name, tests, InstrumentingSmartRunner.fromRunner(runner, baseDir))); | ||
| } | ||
| addFilter(new UniqueFilter()); | ||
| } | ||
|
|
||
| @Override | ||
| public DetectionRound results() throws Exception { | ||
| return makeDts(origResult, runList(testShuffler.tuscanIntraClassOrder(absoluteRound.get()))); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
idflakies-core/src/test/java/edu/illinois/TuscanIntraClassTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| package edu.illinois; | ||
|
|
||
| import java.util.*; | ||
|
|
||
| import org.junit.Test; | ||
| import org.junit.Assert; | ||
|
|
||
| import edu.illinois.cs.dt.tools.detection.TestShuffler; | ||
| import edu.illinois.cs.dt.tools.detection.detectors.TuscanIntraClassDetector; | ||
|
|
||
| public class TuscanIntraClassTest { | ||
| @Test | ||
| public void test() throws Exception { | ||
| String[] testArray = { | ||
| "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncodingByMozilla", | ||
| "cn.edu.hfut.dmic.webcollector.util.CharsetDetectorTest.testGuessEncoding", | ||
| "cn.edu.hfut.dmic.webcollector.util.CrawlDatumTest.testKey", | ||
| "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testBerkeleyDBInjector", | ||
| "cn.edu.hfut.dmic.webcollector.util.DBManagerTest.testRocksDBInjector", | ||
| "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAdd", | ||
| "cn.edu.hfut.dmic.webcollector.util.CrawlDatumsTest.testAddAndReturn", | ||
| "cn.edu.hfut.dmic.webcollector.util.MetaTest.testMetaSetterAndGetter", | ||
| "cn.edu.hfut.dmic.webcollector.util.OkHttpRequesterTest.testHttpCode" | ||
| }; | ||
| List<String> tests = Arrays.asList(testArray); | ||
| TestShuffler testShuffler = new TestShuffler("", 0, tests, null); | ||
| HashMap<String, List<String>> classToMethods = generateClassToMethods(tests); | ||
|
|
||
| int maxMethodSize = TuscanIntraClassDetector.findMaxMethodSize(classToMethods); | ||
| if (maxMethodSize == 3 || maxMethodSize == 5) { | ||
| maxMethodSize++; | ||
| } | ||
| int rounds; | ||
| int classSize = classToMethods.keySet().size(); | ||
| if (classSize == 3 || classSize == 5) { | ||
| classSize++; | ||
| } | ||
| if (classSize > maxMethodSize) { | ||
| rounds = classSize; | ||
| } else { | ||
| rounds = maxMethodSize; | ||
| } | ||
|
|
||
| // Each List inside a set is basically a pair | ||
| Set<List<String>> allClassPairs = generateAllPairs(tests, false); | ||
| Set<List<String>> tuscanCoveredClassPairs = tuscanClassPairs(rounds, tests, testShuffler); | ||
|
|
||
| Assert.assertEquals(allClassPairs, tuscanCoveredClassPairs); | ||
|
|
||
| Set<List<String>> allMethodPairs = generateAllPairs(tests, true); | ||
| Set<List<String>> tuscanCoveredMethodPairs = tuscanMethodPairs(rounds, tests, testShuffler); | ||
|
|
||
| Assert.assertEquals(allMethodPairs, tuscanCoveredMethodPairs); | ||
| } | ||
|
|
||
| public static HashMap<String, List<String>> generateClassToMethods(List<String> tests) { | ||
| HashMap<String, List<String>> classToMethods = new HashMap<>(); | ||
| for (final String test : tests) { | ||
| final String className = TestShuffler.className(test); | ||
| if (!classToMethods.containsKey(className)) { | ||
| classToMethods.put(className, new ArrayList<>()); | ||
| } | ||
| classToMethods.get(className).add(test); | ||
| } | ||
| return classToMethods; | ||
| } | ||
|
|
||
| public static Set<List<String>> generateAllPairs(List<String> tests) { | ||
| Set<List<String>> allPairs = new LinkedHashSet<List<String>>(); | ||
| for (int i = 0; i < tests.size(); i++) { | ||
| for (int j = 0; j < tests.size(); j++) { | ||
| if (!tests.get(i).equals(tests.get(j))) { | ||
| List<String> newPair = new ArrayList<String>(); | ||
| newPair.add(tests.get(i)); | ||
| newPair.add(tests.get(j)); | ||
| allPairs.add(newPair); | ||
| } | ||
| } | ||
| } | ||
| return allPairs; | ||
| } | ||
|
|
||
| private static Set<List<String>> generateAllPairs(List<String> tests, boolean isMethods) { | ||
| // Generates all pairs with a naive algorithm for comparison with tuscan-intra-class method | ||
| Set<List<String>> allPairs = new LinkedHashSet<List<String>>(); | ||
| for (int i = 0; i < tests.size(); i++) { | ||
| for (int j = 0; j < tests.size(); j++) { | ||
| String className1 = TestShuffler.className(tests.get(i)); | ||
| String className2 = TestShuffler.className(tests.get(j)); | ||
| List<String> newPair = new ArrayList<String>(); | ||
| if (!isMethods && !className1.equals(className2)) { | ||
| newPair.add(className1); | ||
| newPair.add(className2); | ||
| allPairs.add(newPair); | ||
| } else if (isMethods && className1.equals(className2) && !tests.get(i).equals(tests.get(j))) { | ||
| newPair.add(tests.get(i)); | ||
| newPair.add(tests.get(j)); | ||
| allPairs.add(newPair); | ||
| } | ||
| } | ||
| } | ||
| return allPairs; | ||
| } | ||
|
|
||
| private static Set<List<String>> tuscanClassPairs(int rounds, List<String> tests, TestShuffler testShuffler) { | ||
| // Generates the class pairs using tuscan-intra-class algorithm | ||
| Set<List<String>> visitedClassPairs = new LinkedHashSet<List<String>>(); | ||
| for (int i = 0; i < rounds; i++) { | ||
| List<String> currentOrder = testShuffler.tuscanIntraClassOrder(i); | ||
| for (int j = 0; j < currentOrder.size() - 1; j++) { | ||
| String className1 = TestShuffler.className(currentOrder.get(j)); | ||
| String className2 = TestShuffler.className(currentOrder.get(j + 1)); | ||
| List<String> newPair = new ArrayList<String>(); | ||
| if (!className1.equals(className2)) { | ||
| newPair.add(className1); | ||
| newPair.add(className2); | ||
| visitedClassPairs.add(newPair); | ||
| } | ||
| } | ||
| } | ||
| return visitedClassPairs; | ||
| } | ||
|
|
||
| private static Set<List<String>> tuscanMethodPairs(int rounds, List<String> tests, TestShuffler testShuffler) { | ||
| // Generates the intra-class method pairs using tuscan-intra-class algorithm | ||
| Set<List<String>> visitedMethodPairs = new LinkedHashSet<List<String>>(); | ||
| for (int i = 0; i < rounds; i++) { | ||
| List<String> currentOrder = testShuffler.tuscanIntraClassOrder(i); | ||
| for (int j = 0; j < currentOrder.size() - 1; j++) { | ||
| String class1 = TestShuffler.className(currentOrder.get(j)); | ||
| String class2 = TestShuffler.className(currentOrder.get(j + 1)); | ||
| if (class1.equals(class2)) { | ||
| List<String> newPair = new ArrayList<String>(); | ||
| newPair.add(currentOrder.get(j)); | ||
| newPair.add(currentOrder.get(j + 1)); | ||
| visitedMethodPairs.add(newPair); | ||
| } | ||
| } | ||
| } | ||
| return visitedMethodPairs; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should add some comment to explain the reasoning/intention behind this loop concerning the class round, so we remember later what is the goal.