-
Notifications
You must be signed in to change notification settings - Fork 46
Socket connection in python fuzzing #1844
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…' into tamarinvs19/utbot-python-sockets # Conflicts: # utbot-python/src/main/kotlin/org/utbot/python/PythonEngine.kt # utbot-python/src/main/resources/requirements.txt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the moment an exception is thrown, or no tests generated for this example:
def test3(x: str) -> bool:
if x[0] == 'b':
if x[1] == 'a':
if x[2] == 'd':
if x[3] == '!':
raise RuntimeError("Very bad")
return True
# Conflicts: # utbot-python/src/main/kotlin/org/utbot/python/PythonEngine.kt # utbot-python/src/main/kotlin/org/utbot/python/PythonTestCaseGenerator.kt # utbot-python/src/main/resources/requirements.txt
…entation in state dict, move up ADDITIONAL_LIMIT, update utbot_executor
data class PythonFeedback( | ||
override val control: Control = Control.CONTINUE, | ||
val result: Trie.Node<Instruction> = Trie.emptyNode(), | ||
val executionFeedback: FuzzingExecutionFeedback? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feedback is used as a part of equals/hashCode, therefore 2 same paths with different result will be recognized as different feedbacks. Is it intented?
fun getOffsetLine(sourceFileContent: String, offset: Int): Int { | ||
return sourceFileContent.take(offset).count { it == '\n' } + 1 | ||
} | ||
|
||
fun <T> weightedRandom(elems: List<T>, weights: List<Double>): T { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can find similar util method in RandomExtension.kt (in module utbot-fuzzing) with name Random.chooseOne. Also, please not, that random in your case doesn't use seed, therefore, every run will be different, that usually is undesirable.
}.first | ||
val value = Random.nextDouble() | ||
return elems[borders.indexOfFirst { it >= value }] | ||
val index = Random.chooseOne(weights.map { it / sum }.toDoubleArray()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The random is still no-seed random. Also, you can pass to the chooseOne just weights.toDoubleArray
. The method chooseOne
does sum
itself, so, there's no need to do it before.
@@ -52,6 +53,18 @@ class PythonEngine( | |||
private val pythonTypeStorage: PythonTypeStorage, | |||
) { | |||
|
|||
private val cache = mutableMapOf<Pair<PythonMethodDescription, List<PythonTreeWrapper>>, PythonExecutionResult>() | |||
|
|||
private fun addExecutionToCache(key: Pair<PythonMethodDescription, List<PythonTreeWrapper>>, result: PythonExecutionResult) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend extracting the cache into a separate class to facilitate further work with it.
Description
Added socket connection between python and kotlin. Now it works 10 times faster then previous verision.
Fixes #1856
How to test
Manual tests
Generate tests for python function, for example, with many branches.
Self-check list
Check off the item if the statement is true. Hint: [x] is a marked item.
Please do not delete the list or its items.