@@ -30,7 +30,6 @@ import java.io.File
3030
3131private val logger = KotlinLogging .logger {}
3232private const val RANDOM_TYPE_FREQUENCY = 6
33- private const val MAX_EXECUTIONS = 50000
3433
3534class PythonTestCaseGenerator (
3635 private val withMinimization : Boolean = true ,
@@ -168,9 +167,7 @@ class PythonTestCaseGenerator(
168167
169168 var feedback: InferredTypeFeedback = SuccessFeedback
170169
171- val fuzzerCancellation = {
172- isCancelled() || limitManager.isCancelled() || (errors.size + executions.size) >= MAX_EXECUTIONS
173- }
170+ val fuzzerCancellation = { isCancelled() || limitManager.isCancelled() }
174171
175172 engine.fuzzing(args, fuzzerCancellation, until).collect {
176173 when (it) {
@@ -182,8 +179,8 @@ class PythonTestCaseGenerator(
182179 }
183180 is InvalidExecution -> {
184181 errors + = it.utError
185- feedback = SuccessFeedback
186- limitManager.addSuccessExecution ()
182+ feedback = InvalidTypeFeedback
183+ limitManager.addInvalidExecution ()
187184 }
188185 is ArgumentsTypeErrorFeedback -> {
189186 feedback = InvalidTypeFeedback
@@ -193,6 +190,19 @@ class PythonTestCaseGenerator(
193190 feedback = InvalidTypeFeedback
194191 limitManager.addInvalidExecution()
195192 }
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+ }
196206 }
197207 limitManager.missedLines = missingLines?.size
198208 }
@@ -213,28 +223,41 @@ class PythonTestCaseGenerator(
213223 val coveredLines = mutableSetOf<Int >()
214224
215225 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" }
238261 }
239262
240263 logger.info(" Collect all test executions for ${method.name} " )
0 commit comments