Skip to content

Commit 3c72e47

Browse files
committed
yet more cleaning and refactoring
1 parent 271e4af commit 3c72e47

20 files changed

Lines changed: 71 additions & 53 deletions

core/src/main/kotlin/org/evomaster/core/Main.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class Main {
271271
solution = phaseHttpOracle(injector, config, epc, solution)
272272
solution = phaseFlaky(injector, config, epc, solution)
273273

274-
epc.startWriteOutput()
274+
epc.markStartingWriteOutput()
275275
val suites = writeTests(injector, solution, controllerInfo)
276276
writeWFCReport(injector, solution, suites)
277277

@@ -300,7 +300,7 @@ class Main {
300300

301301
solution.statistics = data.toMutableList()
302302

303-
epc.finishSession()
303+
epc.markFinishedSession()
304304

305305
return solution
306306
}
@@ -425,7 +425,7 @@ class Main {
425425
return when (config.problemType) {
426426
EMConfig.ProblemType.REST -> {
427427
LoggingUtil.getInfoLogger().info("Starting to apply flaky detection")
428-
epc.startFlakiness()
428+
epc.markStartingFlakiness()
429429

430430
val flakinessDetector = injector.getInstance(Key.get(object : TypeLiteral<FlakinessDetector<RestIndividual>>() {}))
431431
flakinessDetector.reexecuteToDetectFlakiness()
@@ -452,7 +452,7 @@ class Main {
452452
}
453453
//apply security testing phase
454454
LoggingUtil.getInfoLogger().info("Starting to apply security testing")
455-
epc.startSecurity()
455+
epc.markStartingSecurity()
456456

457457
//TODO might need to reset stc, and print some updated info again
458458

@@ -479,7 +479,7 @@ class Main {
479479

480480
return if (config.httpOracles && config.problemType == EMConfig.ProblemType.REST) {
481481
LoggingUtil.getInfoLogger().info("Starting to apply HTTP")
482-
epc.startHttpOracles()
482+
epc.markStartingAdditionalOracles()
483483

484484
val httpSemanticsService = injector.getInstance(HttpSemanticsService::class.java)
485485
httpSemanticsService.applyHttpSemanticsPhase()
@@ -832,7 +832,7 @@ class Main {
832832

833833
val config = injector.getInstance(EMConfig::class.java)
834834
val epc = injector.getInstance(ExecutionPhaseController::class.java)
835-
epc.startSearch()
835+
epc.markStartingSearch()
836836

837837
if (!config.blackBox || config.bbExperiments) {
838838
val rc = injector.getInstance(RemoteController::class.java)

core/src/main/kotlin/org/evomaster/core/search/service/SearchAlgorithm.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ abstract class SearchAlgorithm<T> where T : Individual {
104104
time.doStopRecording()
105105

106106
if(config.minimize){
107-
epc.startMinimization()
107+
epc.markStartingMinimization()
108108

109109
minimizer.doStartTheTimer()
110110
minimizer.minimizeMainActionsPerCoveredTargetInArchive()

core/src/main/kotlin/org/evomaster/core/search/service/time/ExecutionPhaseController.kt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ import org.evomaster.core.logging.LoggingUtil
55
import org.evomaster.core.utils.TimeUtils
66
import javax.inject.Inject
77

8+
/**
9+
* Service used to keep track of which phase of the fuzzing we are currently in,
10+
* and how long we have spent in them.
11+
*/
812
class ExecutionPhaseController {
913

1014
enum class Phase{
1115
NOT_STARTED,
1216
SEARCH,
1317
MINIMIZATION,
1418
SECURITY,
15-
HTTP_ORACLES,
19+
ADDITIONAL_ORACLES,
1620
FLAKINESS,
1721
WRITE_OUTPUT,
1822
FINISHED
@@ -37,46 +41,46 @@ class ExecutionPhaseController {
3741

3842
fun isInSearch() = phase == Phase.SEARCH
3943

40-
fun startSearch() {
44+
fun markStartingSearch() {
4145
if(isRunning()){
4246
throw IllegalStateException("Illegal state to start new search: $phase")
4347
}
4448
startPhase(Phase.SEARCH)
4549
}
4650

47-
fun finishSession() {
51+
fun markFinishedSession() {
4852
startPhase(Phase.FINISHED)
4953
}
5054

51-
fun startMinimization() {
55+
fun markStartingMinimization() {
5256
if(!isRunning()) {
5357
throw IllegalStateException("Illegal state to start minimization: $phase")
5458
}
5559
startPhase(Phase.MINIMIZATION)
5660
}
5761

58-
fun startSecurity(){
62+
fun markStartingSecurity(){
5963
if(!isRunning()) {
6064
throw IllegalStateException("Illegal state to start security: $phase")
6165
}
6266
startPhase(Phase.SECURITY)
6367
}
6468

65-
fun startFlakiness() {
69+
fun markStartingFlakiness() {
6670
if (!isRunning()) {
6771
throw IllegalStateException("Illegal state to start flakiness detection: $phase")
6872
}
6973
startPhase(Phase.FLAKINESS)
7074
}
7175

72-
fun startHttpOracles(){
76+
fun markStartingAdditionalOracles(){
7377
if(!isRunning()) {
74-
throw IllegalStateException("Illegal state to start http oracles: $phase")
78+
throw IllegalStateException("Illegal state to start additional oracles: $phase")
7579
}
76-
startPhase(Phase.HTTP_ORACLES)
80+
startPhase(Phase.ADDITIONAL_ORACLES)
7781
}
7882

79-
fun startWriteOutput (){
83+
fun markStartingWriteOutput (){
8084
if(!isRunning()) {
8185
throw IllegalStateException("Illegal state to start write output: $phase")
8286
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.evomaster.core.search.service.time
2+
3+
/**
4+
* A service representing one phase of fuzzing that is time-boxed.
5+
* This means that the phase should not run more than a certain amount of time.
6+
* If such limit is reached, the phase is prematurely stopped.
7+
* Ideally, most of the time we would expect the phase to finish way earlier than the timeout.
8+
*
9+
* Note: this is quite different from typical "search" phase, where we usually run for all
10+
* the available budget
11+
*/
12+
interface TimeBoxedPhase {
13+
14+
fun applyPhase()
15+
16+
fun hasPhaseTimedOut(): Boolean
17+
}

core/src/test/kotlin/org/evomaster/core/search/algorithms/BreederGeneticAlgorithmTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ class BreederGeneticAlgorithmTest {
4444
config.stoppingCriterion = EMConfig.StoppingCriterion.ACTION_EVALUATIONS
4545

4646
val epc = injector.getInstance(ExecutionPhaseController::class.java)
47-
epc.startSearch()
47+
epc.markStartingSearch()
4848
val solution = breederGA.search()
49-
epc.finishSession()
49+
epc.markFinishedSession()
5050

5151
assertTrue(solution.individuals.size == 1)
5252
assertEquals(OneMaxSampler.DEFAULT_N.toDouble(), solution.overall.computeFitnessScore(), 0.001)

core/src/test/kotlin/org/evomaster/core/search/algorithms/CellularGeneticAlgorithmTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ class CellularGeneticAlgorithmTest {
8888
config.stoppingCriterion = EMConfig.StoppingCriterion.ACTION_EVALUATIONS
8989

9090
val epc = injector.getInstance(ExecutionPhaseController::class.java)
91-
epc.startSearch()
91+
epc.markStartingSearch()
9292
val solution = cga.search()
93-
epc.finishSession()
93+
epc.markFinishedSession()
9494

9595
assertTrue(solution.individuals.size == 1)
9696
assertEquals(OneMaxSampler.DEFAULT_N.toDouble(), solution.overall.computeFitnessScore(), 0.001)

core/src/test/kotlin/org/evomaster/core/search/algorithms/CroAlgorithmTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ class CroAlgorithmTest {
5656
config.stoppingCriterion = EMConfig.StoppingCriterion.ACTION_EVALUATIONS
5757

5858
val epc = injector.getInstance(ExecutionPhaseController::class.java)
59-
epc.startSearch()
59+
epc.markStartingSearch()
6060
val solution = cro.search()
61-
epc.finishSession()
61+
epc.markFinishedSession()
6262

6363
assertTrue(solution.individuals.size == 1)
6464
assertEquals(OneMaxSampler.DEFAULT_N.toDouble(), solution.overall.computeFitnessScore(), 0.001)

core/src/test/kotlin/org/evomaster/core/search/algorithms/LIPSAlgorithmTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ class LIPSAlgorithmTest {
4242
config.stoppingCriterion = EMConfig.StoppingCriterion.ACTION_EVALUATIONS
4343

4444
val epc = injector.getInstance(ExecutionPhaseController::class.java)
45-
epc.startSearch()
45+
epc.markStartingSearch()
4646
val solution = lips.search()
47-
epc.finishSession()
47+
epc.markFinishedSession()
4848

4949
assertTrue(solution.individuals.size == 1)
5050
assertEquals(

core/src/test/kotlin/org/evomaster/core/search/algorithms/MioAlgorithmOnConstantTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ class MioAlgorithmOnConstantTest {
3636
config.maxEvaluations = 200
3737
config.stoppingCriterion = EMConfig.StoppingCriterion.ACTION_EVALUATIONS
3838
val epc = injector.getInstance(ExecutionPhaseController::class.java)
39-
epc.startSearch()
39+
epc.markStartingSearch()
4040

4141
val solution = mio.search()
4242

4343
Assertions.assertEquals(1.0, solution.overall.computeFitnessScore(), 0.001);
4444
Assertions.assertEquals(1, solution.individuals.size)
4545
}
46-
}
46+
}

core/src/test/kotlin/org/evomaster/core/search/algorithms/MioAlgorithmOnOneMaxTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class MioAlgorithmOnOneMaxTest {
3737
config.maxEvaluations = 30000
3838
config.stoppingCriterion = EMConfig.StoppingCriterion.ACTION_EVALUATIONS
3939
val epc = injector.getInstance(ExecutionPhaseController::class.java)
40-
epc.startSearch()
40+
epc.markStartingSearch()
4141

4242
val n = 20
4343
sampler.n = n
@@ -47,4 +47,4 @@ class MioAlgorithmOnOneMaxTest {
4747
Assertions.assertEquals(n.toDouble(), solution.overall.computeFitnessScore(), 0.001);
4848
Assertions.assertEquals(1, solution.individuals.size)
4949
}
50-
}
50+
}

0 commit comments

Comments
 (0)