Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit63e4282

Browse files
committed
Improve fuzzing process for generics
1 parentd9c0d49 commit63e4282

File tree

7 files changed

+125
-52
lines changed

7 files changed

+125
-52
lines changed

‎utbot-python/src/main/kotlin/org/utbot/python/engine/fuzzing/FuzzingEngine.kt‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@ import org.utbot.python.fuzzing.PythonMethodDescription
5656
importorg.utbot.python.newtyping.PythonTypeHintsStorage
5757
importorg.utbot.python.newtyping.ast.visitor.constants.ConstantCollector
5858
importorg.utbot.python.newtyping.ast.visitor.hints.HintCollector
59+
importorg.utbot.python.newtyping.general.FunctionType
5960
importorg.utbot.python.newtyping.general.UtType
6061
importorg.utbot.python.newtyping.inference.InvalidTypeFeedback
6162
importorg.utbot.python.newtyping.inference.SuccessFeedback
6263
importorg.utbot.python.newtyping.inference.baseline.BaselineAlgorithm
64+
importorg.utbot.python.newtyping.inference.baseline.MethodAndVars
6365
importorg.utbot.python.newtyping.mypy.MypyInfoBuild
6466
importorg.utbot.python.newtyping.mypy.MypyReportLine
6567
importorg.utbot.python.newtyping.mypy.getErrorNumber
@@ -72,14 +74,13 @@ import org.utbot.python.utils.TestGenerationLimitManager
7274
importorg.utbot.python.utils.TimeoutMode
7375
importorg.utbot.python.utils.camelToSnakeCase
7476
importorg.utbot.python.utils.convertToTime
75-
importorg.utbot.python.utils.separateUntil
7677
importorg.utbot.summary.fuzzer.names.TestSuggestedInfo
7778
importjava.net.ServerSocket
7879
importkotlin.random.Random
7980

8081
privateval logger=KotlinLogging.logger {}
8182
privateconstvalRANDOM_TYPE_FREQUENCY=6
82-
privateconstvalMINIMAL_TIMEOUT_FOR_SUBSTITUTION=4_000// ms
83+
privateconstvalMINIMAL_TIMEOUT_FOR_SUBSTITUTION=7_000// ms
8384

8485
classFuzzingEngine(
8586
valmethod:PythonMethod,
@@ -110,18 +111,16 @@ class FuzzingEngine(
110111
val now=System.currentTimeMillis()
111112
val filterModifications= modifications
112113
.take(minOf(modifications.size, maxOf(((until- now)/MINIMAL_TIMEOUT_FOR_SUBSTITUTION).toInt(),1)))
113-
filterModifications
114-
.forEachIndexed { index, (modifiedMethod, additionalVars)->
115-
logger.info {"Modified method:${modifiedMethod.methodSignature()}" }
116-
val localUntil= separateUntil(until, index, filterModifications.size)
117-
logger.info {"Fuzzing local until:${localUntil.convertToTime()}" }
118-
generateTests(modifiedMethod, additionalVars, localUntil)
114+
.map { (modifiedMethod, additionalVars)->
115+
logger.info {"Substitution:${modifiedMethod.methodSignature()}" }
116+
MethodAndVars(modifiedMethod, additionalVars)
119117
}
118+
generateTests(method, filterModifications, until)
120119
}
121120

122121
privatefungenerateTests(
123122
method:PythonMethod,
124-
additionalVars:String,
123+
methodModifications:List<MethodAndVars>,
125124
until:Long,
126125
) {
127126
val timeoutLimitManager=TestGenerationLimitManager(
@@ -140,7 +139,8 @@ class FuzzingEngine(
140139
typeStorage,
141140
hintCollector.result,
142141
configuration.pythonPath,
143-
method,
142+
MethodAndVars(method,""),
143+
methodModifications,
144144
configuration.sysPathDirectories,
145145
configuration.testFileInformation.moduleName,
146146
namesInModule,
@@ -151,7 +151,6 @@ class FuzzingEngine(
151151
getOffsetLine(sourceFileContent, method.ast.endOffset)
152152
),
153153
mypyStorage.buildRoot.configFile,
154-
additionalVars,
155154
randomTypeFrequency=RANDOM_TYPE_FREQUENCY,
156155
dMypyTimeout= configuration.timeoutForRun,
157156
)
@@ -200,14 +199,16 @@ class FuzzingEngine(
200199
}
201200
logger.debug {"Executor manager was created successfully" }
202201

202+
val initialType= typeInferenceAlgorithm.expandState()asFunctionType
203+
203204
val pmd=PythonMethodDescription(
204205
method.name,
205206
constants,
206207
typeStorage,
207208
Trie(PyInstruction::id),
208209
Random(0),
209210
TestGenerationLimitManager(ExecutionWithTimoutMode, until, isRootManager=true),
210-
method.methodType,
211+
initialType,
211212
)
212213

213214
try {

‎utbot-python/src/main/kotlin/org/utbot/python/engine/fuzzing/typeinference/FunctionAnnotationUtils.kt‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ private val BAD_TYPES = setOf(
2121
"builtins.super",
2222
"builtins.type",
2323
"builtins.slice",
24+
"builtins.range",
25+
"builtins.memoryview",
26+
"builtins.object",
2427
)
2528

2629
fungetCandidates(param:TypeParameter,typeStorage:PythonTypeHintsStorage):List<UtType> {
@@ -44,7 +47,7 @@ fun getCandidates(param: TypeParameter, typeStorage: PythonTypeHintsStorage): Li
4447
fungenerateTypesAfterSubstitution(type:UtType,typeStorage:PythonTypeHintsStorage):List<UtType> {
4548
val params= type.getBoundedParameters()
4649
returnPriorityCartesianProduct(params.map { getCandidates(it, typeStorage) }).getSequence()
47-
.filter {it.all { it.pythonTypeName()!inBAD_TYPES } }
50+
.filter {types-> types.all { it.pythonTypeName()!inBAD_TYPES } }
4851
.map { subst->
4952
DefaultSubstitutionProvider.substitute(type, (params zip subst).associate { it })
5053
}.take(MAX_SUBSTITUTIONS).toList()

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

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,46 @@ package org.utbot.python.fuzzing
22

33
importmu.KotlinLogging
44
importorg.utbot.fuzzer.FuzzedContext
5-
importorg.utbot.fuzzing.*
5+
importorg.utbot.fuzzing.Control
6+
importorg.utbot.fuzzing.Description
7+
importorg.utbot.fuzzing.Feedback
8+
importorg.utbot.fuzzing.Fuzzing
9+
importorg.utbot.fuzzing.Seed
10+
importorg.utbot.fuzzing.Statistic
611
importorg.utbot.fuzzing.utils.Trie
712
importorg.utbot.python.coverage.PyInstruction
813
importorg.utbot.python.engine.ExecutionFeedback
914
importorg.utbot.python.framework.api.python.PythonTree
10-
importorg.utbot.python.fuzzing.provider.*
15+
importorg.utbot.python.fuzzing.provider.BoolValueProvider
16+
importorg.utbot.python.fuzzing.provider.BytearrayValueProvider
17+
importorg.utbot.python.fuzzing.provider.BytesValueProvider
18+
importorg.utbot.python.fuzzing.provider.ComplexValueProvider
19+
importorg.utbot.python.fuzzing.provider.ConstantValueProvider
20+
importorg.utbot.python.fuzzing.provider.DictValueProvider
21+
importorg.utbot.python.fuzzing.provider.FloatValueProvider
22+
importorg.utbot.python.fuzzing.provider.IntValueProvider
23+
importorg.utbot.python.fuzzing.provider.IteratorValueProvider
24+
importorg.utbot.python.fuzzing.provider.ListValueProvider
25+
importorg.utbot.python.fuzzing.provider.NoneValueProvider
26+
importorg.utbot.python.fuzzing.provider.OptionalValueProvider
27+
importorg.utbot.python.fuzzing.provider.RePatternValueProvider
28+
importorg.utbot.python.fuzzing.provider.ReduceValueProvider
29+
importorg.utbot.python.fuzzing.provider.SetValueProvider
30+
importorg.utbot.python.fuzzing.provider.StrValueProvider
31+
importorg.utbot.python.fuzzing.provider.SubtypeValueProvider
32+
importorg.utbot.python.fuzzing.provider.TupleFixSizeValueProvider
33+
importorg.utbot.python.fuzzing.provider.TupleValueProvider
34+
importorg.utbot.python.fuzzing.provider.TypeAliasValueProvider
35+
importorg.utbot.python.fuzzing.provider.UnionValueProvider
1136
importorg.utbot.python.fuzzing.provider.utils.isAny
12-
importorg.utbot.python.newtyping.*
37+
importorg.utbot.python.newtyping.PythonTypeHintsStorage
1338
importorg.utbot.python.newtyping.general.FunctionType
1439
importorg.utbot.python.newtyping.general.UtType
1540
importorg.utbot.python.newtyping.inference.InferredTypeFeedback
1641
importorg.utbot.python.newtyping.inference.InvalidTypeFeedback
1742
importorg.utbot.python.newtyping.inference.SuccessFeedback
1843
importorg.utbot.python.newtyping.inference.baseline.BaselineAlgorithm
44+
importorg.utbot.python.newtyping.pythonTypeRepresentation
1945
importorg.utbot.python.utils.ExecutionWithTimoutMode
2046
importorg.utbot.python.utils.FakeWithTimeoutMode
2147
importorg.utbot.python.utils.TestGenerationLimitManager
@@ -167,7 +193,6 @@ class PythonFuzzing(
167193
stats:Statistic<UtType,PythonFuzzedValue>
168194
):Boolean {
169195
if (globalIsCancelled()) {
170-
logger.warn {"Cancellation in fuzzing" }
171196
returntrue
172197
}
173198
if (description.limitManager.isCancelled()|| description.parameters.any { it.isAny() }) {

‎utbot-python/src/main/kotlin/org/utbot/python/newtyping/inference/TypeInferenceProcessor.kt‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,31 @@ import org.parsers.python.PythonParser
55
importorg.parsers.python.ast.ClassDefinition
66
importorg.parsers.python.ast.FunctionDefinition
77
importorg.utbot.python.PythonBaseMethod
8-
importorg.utbot.python.newtyping.*
8+
importorg.utbot.python.newtyping.PythonFunctionDefinition
9+
importorg.utbot.python.newtyping.PythonTypeHintsStorage
910
importorg.utbot.python.newtyping.ast.parseClassDefinition
1011
importorg.utbot.python.newtyping.ast.parseFunctionDefinition
1112
importorg.utbot.python.newtyping.ast.visitor.Visitor
1213
importorg.utbot.python.newtyping.ast.visitor.hints.HintCollector
1314
importorg.utbot.python.newtyping.general.CompositeType
1415
importorg.utbot.python.newtyping.general.UtType
16+
importorg.utbot.python.newtyping.getPythonAttributeByName
1517
importorg.utbot.python.newtyping.inference.baseline.BaselineAlgorithm
16-
importorg.utbot.python.newtyping.mypy.*
18+
importorg.utbot.python.newtyping.inference.baseline.MethodAndVars
19+
importorg.utbot.python.newtyping.mypy.GlobalNamesStorage
20+
importorg.utbot.python.newtyping.mypy.MypyBuildDirectory
21+
importorg.utbot.python.newtyping.mypy.MypyInfoBuild
22+
importorg.utbot.python.newtyping.mypy.dropInitFile
23+
importorg.utbot.python.newtyping.mypy.getErrorNumber
24+
importorg.utbot.python.newtyping.mypy.readMypyAnnotationStorageAndInitialErrors
25+
importorg.utbot.python.newtyping.pythonTypeRepresentation
1726
importorg.utbot.python.newtyping.utils.getOffsetLine
18-
importorg.utbot.python.utils.*
27+
importorg.utbot.python.utils.Cleaner
28+
importorg.utbot.python.utils.Fail
29+
importorg.utbot.python.utils.Optional
30+
importorg.utbot.python.utils.RequirementsUtils
31+
importorg.utbot.python.utils.Success
32+
importorg.utbot.python.utils.TemporaryFileManager
1933
importjava.io.File
2034
importjava.nio.file.Path
2135
importjava.nio.file.Paths
@@ -92,7 +106,8 @@ class TypeInferenceProcessor(
92106
typeStorage,
93107
collector.result,
94108
pythonPath,
95-
pythonMethod,
109+
MethodAndVars(pythonMethod,""),
110+
emptyList(),
96111
directoriesForSysPath,
97112
moduleOfSourceFile,
98113
namesInModule,
@@ -103,7 +118,6 @@ class TypeInferenceProcessor(
103118
getOffsetLine(sourceFileContent, pythonMethod.ast.endOffset)
104119
),
105120
mypyBuild.buildRoot.configFile,
106-
"",
107121
dMypyTimeout=null
108122
)
109123

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp