-
Notifications
You must be signed in to change notification settings - Fork 18
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
JVM test framework #48
Conversation
usvm-jvm-instrumentation/src/main/kotlin/org/usvm/instrumentation/mock/MockClassRebuilder.kt
Outdated
Show resolved
Hide resolved
usvm-jvm-instrumentation/src/main/kotlin/org/usvm/instrumentation/rd/RdUtils.kt
Show resolved
Hide resolved
usvm-jvm-instrumentation/src/main/kotlin/org/usvm/instrumentation/rd/UTestExecutor.kt
Outdated
Show resolved
Hide resolved
usvm-jvm-instrumentation/src/main/kotlin/org/usvm/instrumentation/rd/UTestExecutor.kt
Outdated
Show resolved
Hide resolved
data class UTestExecutionSuccessResult( | ||
val trace: List<JcInst>?, | ||
val result: UTestValueDescriptor?, | ||
val initialState: UTestExecutionState, | ||
val resultState: UTestExecutionState | ||
): UTestExecutionResult() |
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.
Where mocks are stored?
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.
Maybe I misunderstood the question.
Mock arguments and instance will be in UTestObjectDescriptor
} | ||
|
||
class UTestClassDescriptor( | ||
val classType: JcType, override val type: JcType |
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.
What is the different between classType
and type
? Is type a raw type: Class
while the classType is Class<Boolean>
?
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.
yes
...ion/src/main/kotlin/org/usvm/instrumentation/testcase/descriptor/StaticDescriptorsBuilder.kt
Outdated
Show resolved
Hide resolved
...tation/src/main/kotlin/org/usvm/instrumentation/testcase/executor/UTestExpressionExecutor.kt
Show resolved
Hide resolved
usvm-jvm-instrumentation/src/main/kotlin/org/usvm/instrumentation/util/jacodb.kt
Outdated
Show resolved
Hide resolved
...rumentation/src/test/kotlin/org/usvm/instrumentation/executor/SimpleUTestConcreteExecutor.kt
Outdated
Show resolved
Hide resolved
e9e8ff6
to
7571dbd
Compare
} | ||
} | ||
classesToReinit.forEach { cl -> | ||
cl.declaredMethods.find { it.name == "generatedClinit0" }?.invoke(null) |
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.
It is better to introduce named constants
val javaVersionSpecificArguments = OpenModulesContainer.javaVersionSpecificArguments | ||
val instrumentedProcessClassName = | ||
InstrumentedProcess::class.qualifiedName ?: error("Can't find instumented process") | ||
listOf(pathToJava.resolve("bin${File.separatorChar}${osSpecificJavaExecutable()}").toString()) + |
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.
It is better to use Paths
API to resolve directory instead of File.separatorChar
private fun deserializeTrace(trace: List<Long>, coveredClasses: List<ClassToId>): List<JcInst> = | ||
trace.map { encodedInst -> | ||
deserializedInstructionsCache.getOrPut(encodedInst) { | ||
val classIdOffset = (2.0.pow(Byte.SIZE_BITS * 3).toLong() - 1) shl (Byte.SIZE_BITS * 5 - 1) |
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.
It is better to move this logic closer with the serializer part
instrumentationProcessRunner.init(lifetime) | ||
} catch (e: Throwable) { | ||
//TODO replace to logger | ||
println("Cant init rdProcess:(") |
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.
missed todo
@Test | ||
@Disabled("Jacodb Method Builder issue with instanceOf") |
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.
Is there any way to bypass this problem and enable tests?
48fc5eb
to
95cba97
Compare
36a9be6
to
cabb4e0
Compare
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.
Looked a bit
...trumentation/src/collectors/java/org/usvm/instrumentation/collector/trace/MockCollector.java
Outdated
Show resolved
Hide resolved
...trumentation/src/collectors/java/org/usvm/instrumentation/collector/trace/MockCollector.java
Outdated
Show resolved
Hide resolved
...trumentation/src/collectors/java/org/usvm/instrumentation/collector/trace/MockCollector.java
Show resolved
Hide resolved
} | ||
} catch (e: TimeoutCancellationException) { | ||
val descriptor = UTestExceptionDescriptor( | ||
type = jcClasspath.findClass<Exception>().toType(), |
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.
Maybe you could extract it into into a lazy field? Or better extract it into a method and a variable?
...-jvm-instrumentation/src/main/kotlin/org/usvm/instrumentation/instrumentation/TraceHelper.kt
Outdated
Show resolved
Hide resolved
val ref = evaluateInModel(heapRef) as UConcreteHeapRef | ||
if (ref.address == NULL_ADDRESS) { | ||
return UTestNullExpression(type) to listOf() | ||
} | ||
// to find a type, we need to understand the source of the object | ||
val typeStream = if (ref.address <= INITIAL_INPUT_ADDRESS) { | ||
// input object | ||
model.typeStreamOf(ref) | ||
} else { | ||
// allocated object | ||
memory.typeStreamOf(ref) | ||
}.filterBySupertype(type) | ||
|
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 code is a copy of the code from "JcTestExecutor", what is the difference? Can we extract common parts?
val resolvedLength = resolveLValue(lengthRef, ctx.cp.int).first as UTestIntExpression | ||
// TODO hack | ||
val length = | ||
if (resolvedLength.value in 0..10_000) { |
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 believe this constant should be extracted and used in all the places by reference
return resolveLValue(elemRef, type.elementType) | ||
} | ||
|
||
//val arrLength = UTestIntExpression(length, ctx.cp.int) |
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.
Why?
instrumentation jar path by environment variable
25fbd04
to
4d86a74
Compare
usvm-jvm-instrumentation/src/main/kotlin/org/usvm/instrumentation/rd/UTestExecutor.kt
Outdated
Show resolved
Hide resolved
usvm-jvm-instrumentation/src/main/kotlin/org/usvm/instrumentation/rd/UTestExecutor.kt
Outdated
Show resolved
Hide resolved
...on/src/main/kotlin/org/usvm/instrumentation/testcase/descriptor/Value2DescriptorConverter.kt
Outdated
Show resolved
Hide resolved
usvm-jvm-instrumentation/src/main/kotlin/org/usvm/instrumentation/util/Jacodb.kt
Outdated
Show resolved
Hide resolved
usvm-jvm-instrumentation/src/main/kotlin/org/usvm/instrumentation/util/UTestUtils.kt
Outdated
Show resolved
Hide resolved
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.
Lets make further improvements and fixes in the following requests to make it easier to track and review
JVM test framework (work in progress)
This framework is designed to run code and get execution information. The program launch script is specified using a special API
Key Features:
TODO's: