Skip to content

Commit da6f9ba

Browse files
committed
Update fuzzing
1 parent 8f4f772 commit da6f9ba

File tree

5 files changed

+64
-22
lines changed

5 files changed

+64
-22
lines changed

utbot-python/src/main/kotlin/org/utbot/python/PythonEngine.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,17 @@ class PythonEngine(
215215
emptyList()
216216
)
217217

218+
var coverageLimit = 15
218219
val coveredLines = initialCoveredLines.toMutableSet()
219220

220221
PythonFuzzing(pythonTypeStorage!!) { description, parameterValues ->
222+
if (coverageLimit < 0)
223+
return@PythonFuzzing PythonFeedback(control = Control.STOP)
224+
225+
if (parameterValues.all { it.classId.name == "UNDEF_VALUE" }) {
226+
coverageLimit--
227+
return@PythonFuzzing PythonFeedback(control = Control.PASS)
228+
}
221229

222230
val (thisObject, modelList) =
223231
if (methodUnderTest.containingPythonClassId == null)
@@ -286,9 +294,12 @@ class PythonEngine(
286294
val coveredAfter = coveredLines.size
287295

288296
if (coveredAfter == coveredBefore)
297+
coverageLimit -= 1
298+
299+
if (coverageLimit == 0)
289300
return@PythonFuzzing PythonFeedback(control = Control.STOP)
290301

291-
return@PythonFuzzing PythonFeedback(control = Control.PASS)
302+
return@PythonFuzzing PythonFeedback(control = Control.CONTINUE)
292303

293304
}.fuzz(pmd)
294305
}

utbot-python/src/main/kotlin/org/utbot/python/PythonTestCaseGenerator.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ object PythonTestCaseGenerator {
9797
PythonTypeStorage.get(storage)
9898
)
9999

100-
var coverageLimit = 10
100+
// var coverageLimit = 10
101101

102102
runBlockingWithCancellationPredicate(isCancelled) {
103103
engine.newFuzzing(args).collect {
@@ -118,16 +118,16 @@ object PythonTestCaseGenerator {
118118
}
119119
val coveredAfter = coveredLines.size
120120

121-
if (coveredAfter == coveredBefore)
122-
coverageLimit -= 1
121+
// if (coveredAfter == coveredBefore)
122+
// coverageLimit -= 1
123+
//
124+
// if (withMinimization && missingLines?.isEmpty() == true) {//&& generated % CHUNK_SIZE == 0)
125+
// coverageLimit = 0
126+
// }
123127

124-
if (withMinimization && missingLines?.isEmpty() == true) {//&& generated % CHUNK_SIZE == 0)
125-
coverageLimit = 0
126-
}
127-
128-
if (coverageLimit == 0) {
129-
isCancelled = {true}
130-
}
128+
// if (coverageLimit == 0) {
129+
// isCancelled = {true}
130+
// }
131131
}
132132
}
133133

utbot-python/src/main/kotlin/org/utbot/python/fuzzing/PythonApi.kt

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import org.utbot.fuzzing.Description
88
import org.utbot.fuzzing.Feedback
99
import org.utbot.fuzzing.Fuzzing
1010
import org.utbot.fuzzing.Seed
11+
import org.utbot.python.framework.api.python.PythonClassId
12+
import org.utbot.python.framework.api.python.PythonTree
1113
import org.utbot.python.framework.api.python.PythonTreeModel
14+
import org.utbot.python.framework.api.python.util.pythonNoneClassId
1215
import org.utbot.python.fuzzing.provider.BoolValueProvider
1316
import org.utbot.python.fuzzing.provider.DictValueProvider
1417
import org.utbot.python.fuzzing.provider.FloatValueProvider
@@ -21,6 +24,7 @@ import org.utbot.python.fuzzing.provider.StrValueProvider
2124
import org.utbot.python.fuzzing.provider.TupleFixSizeValueProvider
2225
import org.utbot.python.fuzzing.provider.TupleValueProvider
2326
import org.utbot.python.fuzzing.provider.UnionValueProvider
27+
import org.utbot.python.fuzzing.value.UndefValue
2428
import org.utbot.python.newtyping.PythonProtocolDescription
2529
import org.utbot.python.newtyping.PythonSubtypeChecker
2630
import org.utbot.python.newtyping.PythonTypeStorage
@@ -67,31 +71,47 @@ fun pythonDefaultValueProviders(idGenerator: IdGenerator<Long>) = listOf(
6771
)
6872

6973
class PythonFuzzing(
70-
val pythonTypeStorage: PythonTypeStorage,
74+
private val pythonTypeStorage: PythonTypeStorage,
7175
val execute: suspend (description: PythonMethodDescription, values: List<PythonTreeModel>) -> PythonFeedback,
7276
) : Fuzzing<Type, PythonTreeModel, PythonMethodDescription, PythonFeedback> {
73-
fun generateDefault(description: PythonMethodDescription, type: Type): Sequence<Seed<Type, PythonTreeModel>> {
74-
val idGenerator = PythonIdGenerator()
75-
return pythonDefaultValueProviders(idGenerator).asSequence().flatMap { provider ->
77+
private fun generateDefault(description: PythonMethodDescription, type: Type, idGenerator: IdGenerator<Long>): Sequence<Seed<Type, PythonTreeModel>> {
78+
var providers = emptyList<Seed<Type, PythonTreeModel>>().asSequence()
79+
pythonDefaultValueProviders(idGenerator).asSequence().forEach { provider ->
7680
if (provider.accept(type)) {
77-
provider.generate(description, type)
78-
} else {
79-
emptySequence()
81+
providers += provider.generate(description, type)
8082
}
8183
}
84+
return providers
8285
}
8386

84-
override fun generate(description: PythonMethodDescription, type: Type): Sequence<Seed<Type, PythonTreeModel>> {
85-
var providers = generateDefault(description, type)
87+
private fun generateSubtype(description: PythonMethodDescription, type: Type, idGenerator: IdGenerator<Long>): Sequence<Seed<Type, PythonTreeModel>> {
88+
var providers = emptyList<Seed<Type, PythonTreeModel>>().asSequence()
8689
if (type.meta is PythonProtocolDescription) {
8790
val subtypes = pythonTypeStorage.allTypes.filter {
8891
PythonSubtypeChecker.checkIfRightIsSubtypeOfLeft(type, it, pythonTypeStorage)
8992
}
90-
subtypes.forEach { providers += generateDefault(description, it) }
93+
subtypes.forEach {
94+
providers += generateDefault(description, it, idGenerator)
95+
// providers += generateSubtype(description, it, idGenerator)
96+
}
9197
}
9298
return providers
9399
}
94100

101+
override fun generate(description: PythonMethodDescription, type: Type): Sequence<Seed<Type, PythonTreeModel>> {
102+
val idGenerator = PythonIdGenerator()
103+
var providers = emptyList<Seed<Type, PythonTreeModel>>().asSequence()
104+
105+
providers += generateDefault(description, type, idGenerator)
106+
providers += generateSubtype(description, type, idGenerator)
107+
108+
if (providers.toList().isEmpty()) {
109+
providers += Seed.Known(UndefValue()) {PythonTreeModel(PythonTree.fromNone(), PythonClassId("UNDEF_VALUE"))}
110+
}
111+
112+
return providers
113+
}
114+
95115
override suspend fun handle(description: PythonMethodDescription, values: List<PythonTreeModel>): PythonFeedback {
96116
return execute(description, values)
97117
}

utbot-python/src/main/kotlin/org/utbot/python/fuzzing/provider/StrValueProvider.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ object StrValueProvider : ValueProvider<Type, PythonTreeModel, PythonMethodDescr
1818
}
1919

2020
override fun generate(description: PythonMethodDescription, type: Type) = sequence {
21-
yieldStrings(StringValue("\"\"")) { value }
21+
yieldStrings(StringValue("\"test\"")) { value }
2222
yieldStrings(StringValue("\"abc\"")) { value }
23+
yieldStrings(StringValue("\"\"")) { value }
2324
}
2425

2526
private suspend fun <T : KnownValue> SequenceScope<Seed<Type, PythonTreeModel>>.yieldStrings(value: T, block: T.() -> Any) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.utbot.python.fuzzing.value
2+
3+
import org.utbot.fuzzing.Mutation
4+
import org.utbot.fuzzing.seeds.KnownValue
5+
6+
class UndefValue : KnownValue {
7+
override fun mutations(): List<Mutation<KnownValue>> {
8+
return emptyList()
9+
}
10+
}

0 commit comments

Comments
 (0)