@@ -30,7 +30,6 @@ import java.io.File
30
30
31
31
private val logger = KotlinLogging .logger {}
32
32
private const val RANDOM_TYPE_FREQUENCY = 6
33
- private const val MAX_EXECUTIONS = 50000
34
33
35
34
class PythonTestCaseGenerator (
36
35
private val withMinimization : Boolean = true ,
@@ -168,9 +167,7 @@ class PythonTestCaseGenerator(
168
167
169
168
var feedback: InferredTypeFeedback = SuccessFeedback
170
169
171
- val fuzzerCancellation = {
172
- isCancelled() || limitManager.isCancelled() || (errors.size + executions.size) >= MAX_EXECUTIONS
173
- }
170
+ val fuzzerCancellation = { isCancelled() || limitManager.isCancelled() }
174
171
175
172
engine.fuzzing(args, fuzzerCancellation, until).collect {
176
173
when (it) {
@@ -182,8 +179,8 @@ class PythonTestCaseGenerator(
182
179
}
183
180
is InvalidExecution -> {
184
181
errors + = it.utError
185
- feedback = SuccessFeedback
186
- limitManager.addSuccessExecution ()
182
+ feedback = InvalidTypeFeedback
183
+ limitManager.addInvalidExecution ()
187
184
}
188
185
is ArgumentsTypeErrorFeedback -> {
189
186
feedback = InvalidTypeFeedback
@@ -193,6 +190,19 @@ class PythonTestCaseGenerator(
193
190
feedback = InvalidTypeFeedback
194
191
limitManager.addInvalidExecution()
195
192
}
193
+ is CachedExecutionFeedback -> {
194
+ when (it.cachedFeedback) {
195
+ is ValidExecution -> {
196
+ limitManager.addSuccessExecution()
197
+ }
198
+ else -> {
199
+ limitManager.addInvalidExecution()
200
+ }
201
+ }
202
+ }
203
+ is FakeNodeFeedback -> {
204
+ limitManager.addFakeNodeExecutions()
205
+ }
196
206
}
197
207
limitManager.missedLines = missingLines?.size
198
208
}
@@ -213,28 +223,41 @@ class PythonTestCaseGenerator(
213
223
val coveredLines = mutableSetOf<Int >()
214
224
215
225
logger.info(" Start test generation for ${method.name} " )
216
- val meta = method.definition.type.pythonDescription() as PythonCallableTypeDescription
217
- val argKinds = meta.argumentKinds
218
- if (argKinds.any { it != PythonCallableTypeDescription .ArgKind .ARG_POS }) {
219
- val now = System .currentTimeMillis()
220
- val firstUntil = (until - now) / 2 + now
221
- val originalDef = method.definition
222
- val shortType = meta.removeNonPositionalArgs(originalDef.type)
223
- val shortMeta = PythonFuncItemDescription (
224
- originalDef.meta.name,
225
- originalDef.meta.args.take(shortType.arguments.size)
226
- )
227
- val additionalVars = originalDef.meta.args
228
- .drop(shortType.arguments.size)
229
- .joinToString(separator= " \n " , prefix= " \n " ) { arg ->
230
- " ${arg.name} : ${pythonAnyType.pythonTypeRepresentation()} " // TODO: better types
231
- }
232
- method.definition = PythonFunctionDefinition (shortMeta, shortType)
233
- val missingLines = methodHandler(method, typeStorage, coveredLines, errors, executions, null , firstUntil, additionalVars)
234
- method.definition = originalDef
235
- methodHandler(method, typeStorage, coveredLines, errors, executions, missingLines, until)
236
- } else {
237
- methodHandler(method, typeStorage, coveredLines, errors, executions, null , until)
226
+ try {
227
+ val meta = method.definition.type.pythonDescription() as PythonCallableTypeDescription
228
+ val argKinds = meta.argumentKinds
229
+ if (argKinds.any { it != PythonCallableTypeDescription .ArgKind .ARG_POS }) {
230
+ val now = System .currentTimeMillis()
231
+ val firstUntil = (until - now) / 2 + now
232
+ val originalDef = method.definition
233
+ val shortType = meta.removeNonPositionalArgs(originalDef.type)
234
+ val shortMeta = PythonFuncItemDescription (
235
+ originalDef.meta.name,
236
+ originalDef.meta.args.take(shortType.arguments.size)
237
+ )
238
+ val additionalVars = originalDef.meta.args
239
+ .drop(shortType.arguments.size)
240
+ .joinToString(separator = " \n " , prefix = " \n " ) { arg ->
241
+ " ${arg.name} : ${pythonAnyType.pythonTypeRepresentation()} " // TODO: better types
242
+ }
243
+ method.definition = PythonFunctionDefinition (shortMeta, shortType)
244
+ val missingLines = methodHandler(
245
+ method,
246
+ typeStorage,
247
+ coveredLines,
248
+ errors,
249
+ executions,
250
+ null ,
251
+ firstUntil,
252
+ additionalVars
253
+ )
254
+ method.definition = originalDef
255
+ methodHandler(method, typeStorage, coveredLines, errors, executions, missingLines, until)
256
+ } else {
257
+ methodHandler(method, typeStorage, coveredLines, errors, executions, null , until)
258
+ }
259
+ } catch (_: OutOfMemoryError ) {
260
+ logger.info { " Out of memory error. Stop test generation process" }
238
261
}
239
262
240
263
logger.info(" Collect all test executions for ${method.name} " )
0 commit comments