Skip to content

Commit

Permalink
Fix: disabled and enabled tests, update jacodb version
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeypospelov committed Jul 10, 2023
1 parent 41dee9f commit e297948
Show file tree
Hide file tree
Showing 27 changed files with 70 additions and 41 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ object Versions {
const val ksmt = "0.5.3"
const val collections = "0.3.5"
const val coroutines = "1.6.4"
const val jcdb = "1.1.2"
const val jcdb = "1.1.3"
const val mockk = "1.13.4"
const val junitParams = "5.9.3"

Expand Down
2 changes: 1 addition & 1 deletion usvm-core/src/main/kotlin/org/usvm/StepScope.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class StepScope<T : UState<Type, Field, *, *>, Type, Field>(
* Forks on a [condition], performing [blockOnTrueState] on a state satisfying [condition] and
* [blockOnFalseState] on a state satisfying [condition].not().
*
* If the [condition], sets underlying state to `null`.
* If the [condition] is unsatisfiable, sets underlying state to `null`.
*
* @return `null` if the [condition] is unsatisfiable.
*/
Expand Down
48 changes: 28 additions & 20 deletions usvm-jvm/src/main/kotlin/org/usvm/machine/JcExprResolver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class JcExprResolver(
}

override fun visitJcNewArrayExpr(expr: JcNewArrayExpr): UExpr<out USort>? = with(ctx) {
val size = resolveJcExpr(expr.dimensions[0])?.asExpr(sizeSort) ?: return null
val size = resolveCast(expr.dimensions[0], ctx.cp.int)?.asExpr(bv32Sort) ?: return null
// TODO: other dimensions ( > 1)
checkNewArrayLength(size) ?: return null
val ref = scope.calcOnState { memory.malloc(expr.type, size) } ?: return null
Expand Down Expand Up @@ -442,7 +442,7 @@ class JcExprResolver(

val arrayDescriptor = arrayDescriptorOf(array.type as JcArrayType)

val idx = resolveJcExpr(index)?.asExpr(bv32Sort) ?: return null
val idx = resolveCast(index, ctx.cp.int)?.asExpr(bv32Sort) ?: return null
val lengthRef = UArrayLengthLValue(arrayRef, arrayDescriptor)
val length = scope.calcOnState { memory.read(lengthRef).asExpr(sizeSort) } ?: return null

Expand Down Expand Up @@ -538,13 +538,11 @@ class JcExprResolver(
expr: JcBinaryExpr,
) = resolveAfterResolved(expr.lhv, expr.rhv) { lhs, rhs ->
// we don't want to have extra casts on booleans
val (wideLhs, wideRhs) = if (lhs.sort == ctx.boolSort && rhs.sort == ctx.boolSort) {
lhs to rhs
if (lhs.sort == ctx.boolSort && rhs.sort == ctx.boolSort) {
resolvePrimitiveCast(operator(lhs, rhs), ctx.cp.boolean, expr.type as JcPrimitiveType)
} else {
(lhs wideWith expr.lhv.type) to (rhs wideWith expr.rhv.type)
operator(lhs wideWith expr.lhv.type, rhs wideWith expr.rhv.type)
}

operator(wideLhs, wideRhs)
}

private fun resolveShiftOperator(
Expand Down Expand Up @@ -581,39 +579,49 @@ class JcExprResolver(
private fun resolveCast(
operand: JcExpr,
type: JcType,
) = when (type) {
is JcRefType -> resolveReferenceCast(operand, type)
is JcPrimitiveType -> resolvePrimitiveCast(operand, type)
else -> error("Unexpected type: $type")
) = resolveAfterResolved(operand) { expr ->
when (type) {
is JcRefType -> resolveReferenceCast(expr, operand.type as JcRefType, type)
is JcPrimitiveType -> resolvePrimitiveCast(expr, operand.type as JcPrimitiveType, type)
else -> error("Unexpected type: $type")
}
}

private fun resolveReferenceCast(operand: JcExpr, type: JcRefType) = resolveAfterResolved(operand) { expr ->
if (!operand.type.isAssignable(type)) {
private fun resolveReferenceCast(
expr: UExpr<out USort>,
typeBefore: JcRefType,
type: JcRefType,
): UExpr<out USort>? {
return if (!typeBefore.isAssignable(type)) {
val isExpr = scope.calcOnState { memory.types.evalIs(expr.asExpr(ctx.addressSort), type) }
?: return@resolveAfterResolved null
?: return null
scope.fork(
isExpr,
blockOnFalseState = {
val ln = lastStmt.lineNumber
val exception = ClassCastException("[class cast exception] $ln")
throwException(exception)
}
) ?: return@resolveAfterResolved null
) ?: return null
expr
} else {
expr
}
}

private fun resolvePrimitiveCast(operand: JcExpr, type: JcPrimitiveType) = resolveAfterResolved(operand) { expr ->
private fun resolvePrimitiveCast(
expr: UExpr<out USort>,
typeBefore: JcPrimitiveType,
type: JcPrimitiveType,
): UExpr<out USort> {
// we need this, because char is unsigned, so it should be widened before a cast
val wideExpr = if (operand.type == ctx.cp.char) {
expr wideWith operand.type
val wideExpr = if (typeBefore == ctx.cp.char) {
expr wideWith typeBefore
} else {
expr
}

when (type) {
return when (type) {
ctx.cp.boolean -> JcUnaryOperator.CastToBoolean(wideExpr)
ctx.cp.short -> JcUnaryOperator.CastToShort(wideExpr)
ctx.cp.int -> JcUnaryOperator.CastToInt(wideExpr)
Expand All @@ -622,7 +630,7 @@ class JcExprResolver(
ctx.cp.double -> JcUnaryOperator.CastToDouble(wideExpr)
ctx.cp.byte -> JcUnaryOperator.CastToByte(wideExpr)
ctx.cp.char -> JcUnaryOperator.CastToChar(wideExpr)
else -> error("Unexpected cast expression: $operand")
else -> error("Unexpected cast expression: ($type) $expr of $typeBefore")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,28 @@ sealed class JcUnaryOperator(
)

object CastToByte : JcUnaryOperator(
onBool = { operand -> operand.wideTo32BitsIfNeeded(false) },
onBv = { operand -> operand.mkNarrow(Byte.SIZE_BITS, signed = true) }
)

object CastToChar : JcUnaryOperator(
onBool = { operand -> operand.wideTo32BitsIfNeeded(false) },
onBv = { operand -> operand.mkNarrow(Char.SIZE_BITS, signed = true) }
)

object CastToShort : JcUnaryOperator(
onBool = { operand -> operand.wideTo32BitsIfNeeded(false) },
onBv = { operand -> operand.mkNarrow(Short.SIZE_BITS, signed = true) }
)

object CastToInt : JcUnaryOperator(
onBool = { operand -> operand.wideTo32BitsIfNeeded(false) },
onBv = { operand -> operand.mkNarrow(Int.SIZE_BITS, signed = true) },
onFp = { operand -> operand.castToBv(Int.SIZE_BITS) }
)

object CastToLong : JcUnaryOperator(
onBool = { operand -> operand.wideTo32BitsIfNeeded(false) },
onBv = { operand -> operand.mkNarrow(Long.SIZE_BITS, signed = true) },
onFp = { operand -> operand.castToBv(Long.SIZE_BITS) }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.usvm.util.isException

internal class GraphTest : JavaMethodTestRunner() {
@Test
@Disabled("Some properties were not discovered at positions (from 0): [0, 1, 2, 3, 4]. Tune coverage zone")
fun testRunFindCycle() {
checkDiscoveredPropertiesWithExceptions(
GraphExample::runFindCycle,
Expand All @@ -35,6 +36,7 @@ internal class GraphTest : JavaMethodTestRunner() {
* TODO: fix Dijkstra algorithm.
*/
@Test
@Disabled("Some properties were not discovered at positions (from 0): [3, 4]. Tune coverage zone")
fun testRunDijkstraWithParameter() {
checkDiscoveredPropertiesWithExceptions(
GraphExample::runDijkstraWithParameter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.usvm.util.isException

class ArrayStoreExceptionExamplesTest : JavaMethodTestRunner() {
@Test
@Disabled("Some properties were not discovered at positions (from 0): [1]. Fix branch coverage")
fun testCorrectAssignmentSamePrimitiveType() {
checkDiscoveredPropertiesWithExceptions(
ArrayStoreExceptionExamples::correctAssignmentSamePrimitiveType,
Expand Down Expand Up @@ -111,6 +112,7 @@ class ArrayStoreExceptionExamplesTest : JavaMethodTestRunner() {
}

@Test
@Disabled("Some properties were not discovered at positions (from 0): [0]. Support generics")
fun testCheckWrongAssignmentOfItself() {
checkDiscoveredPropertiesWithExceptions(
ArrayStoreExceptionExamples::checkWrongAssignmentOfItself,
Expand All @@ -120,6 +122,7 @@ class ArrayStoreExceptionExamplesTest : JavaMethodTestRunner() {
}

@Test
@Disabled("Some properties were not discovered at positions (from 0): [0]. Support generics")
fun testCheckGoodAssignmentOfItself() {
checkDiscoveredPropertiesWithExceptions(
ArrayStoreExceptionExamples::checkGoodAssignmentOfItself,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ internal class IntArrayBasicsTest : JavaMethodTestRunner() {
}

@Test
@Disabled("Some properties were not discovered at positions (from 0): [3]. Fix branch coverage")
fun testReversed() {
checkDiscoveredProperties(
IntArrayBasics::reversed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ internal class PrimitiveArraysTest : JavaMethodTestRunner() {
}

@Test
@Disabled("Sort mismatch")
fun testByteArray() {
checkDiscoveredPropertiesWithExceptions(
PrimitiveArrays::byteArray,
Expand All @@ -51,7 +50,6 @@ internal class PrimitiveArraysTest : JavaMethodTestRunner() {
}

@Test
@Disabled("Sort mismatch")
fun testShortArray() {
checkDiscoveredPropertiesWithExceptions(
PrimitiveArrays::shortArray,
Expand All @@ -64,7 +62,6 @@ internal class PrimitiveArraysTest : JavaMethodTestRunner() {
}

@Test
@Disabled("Sort mismatch")
fun testCharArray() {
checkDiscoveredPropertiesWithExceptions(
PrimitiveArrays::charArray,
Expand Down Expand Up @@ -139,7 +136,6 @@ internal class PrimitiveArraysTest : JavaMethodTestRunner() {
}

@Test
@Disabled("Sort mismatch")
fun testByteSizeAndIndex() {
checkDiscoveredProperties(
PrimitiveArrays::byteSizeAndIndex,
Expand All @@ -151,7 +147,6 @@ internal class PrimitiveArraysTest : JavaMethodTestRunner() {
}

@Test
@Disabled("Sort mismatch")
fun testShortSizeAndIndex() {
checkDiscoveredProperties(
PrimitiveArrays::shortSizeAndIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ internal class ArrayCastExampleTest : JavaMethodTestRunner() {
}

@Test
@Disabled("java.lang.ClassNotFoundException: sun.rmi.rmic.BatchEnvironment\$Path. Fix types priority")
fun testCastFromCollections() {
checkDiscoveredProperties(
ArrayCastExample::castFromCollections,
Expand All @@ -138,6 +139,7 @@ internal class ArrayCastExampleTest : JavaMethodTestRunner() {
}

@Test
@Disabled("java.lang.ClassNotFoundException: sun.rmi.rmic.BatchEnvironment\$Path. Fix types priority")
fun testCastFromIterable() {
checkDiscoveredProperties(
ArrayCastExample::castFromIterable,
Expand All @@ -149,6 +151,7 @@ internal class ArrayCastExampleTest : JavaMethodTestRunner() {
}

@Test
@Disabled("java.lang.ClassNotFoundException: sun.rmi.rmic.BatchEnvironment\$Path. Fix types priority")
fun testCastFromIterableToCollection() {
checkDiscoveredProperties(
ArrayCastExample::castFromIterableToCollection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.usvm.test.util.checkers.eq

internal class GenericCastExampleTest : JavaMethodTestRunner() {
@Test
@Disabled("Expected exactly 5 executions, but 1 found. Support generics")
fun testCompareTwoNumbers() {
checkDiscoveredProperties(
GenericCastExample::compareTwoNumbers,
Expand All @@ -21,6 +22,7 @@ internal class GenericCastExampleTest : JavaMethodTestRunner() {
}

@Test
@Disabled("Expected exactly 3 executions, but 2 found. Support generics")
fun testGetGenericFieldValue() {
checkDiscoveredProperties(
GenericCastExample::getGenericFieldValue,
Expand All @@ -32,6 +34,7 @@ internal class GenericCastExampleTest : JavaMethodTestRunner() {
}

@Test
@Disabled("List is empty. Support generics")
fun testCompareGenericField() {
checkDiscoveredProperties(
GenericCastExample::compareGenericField,
Expand All @@ -54,6 +57,7 @@ internal class GenericCastExampleTest : JavaMethodTestRunner() {
}

@Test
@Disabled("List is empty. Support generics")
fun testSumFromArrayOfGenerics() {
checkDiscoveredProperties(
GenericCastExample::sumFromArrayOfGenerics,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.usvm.test.util.checkers.eq


@Suppress("INACCESSIBLE_TYPE")
@Disabled("Expected exactly 2 executions, but 1 found. Fix inner classes")
internal class ClassWithStaticAndInnerClassesTest : JavaMethodTestRunner() {
@Test
fun testUsePrivateStaticClassWithPrivateField() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.usvm.samples.controlflow

import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.usvm.CoverageZone
import org.usvm.PathSelectionStrategy
import org.usvm.UMachineOptions
import org.usvm.samples.JavaMethodTestRunner
Expand Down Expand Up @@ -74,8 +73,7 @@ internal class CyclesTest : JavaMethodTestRunner() {

@Test
@Disabled("Some properties were not discovered at positions (from 0): [0]. Tune coverage zone")
@Suppress("UNUSED_PARAMETER")
fun testCallInnerWhile(options: UMachineOptions) {
fun testCallInnerWhile() {
checkDiscoveredProperties(
Cycles::callInnerWhile,
between(1..2),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class ClassWithEnumTest : JavaMethodTestRunner() {
}

@Test
@Disabled("Some properties were not discovered at positions (from 0): [1]. Support enums")
fun testNullParameter() {
checkDiscoveredProperties(
ClassWithEnum::nullEnumAsParameter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ComplexEnumExamplesTest : JavaMethodTestRunner() {
}

@Test
@Disabled("Some properties were not discovered at positions (from 0): [0]")
fun testCountEqualColors() {
checkDiscoveredProperties(
ComplexEnumExamples::countEqualColors,
Expand All @@ -62,6 +63,7 @@ class ComplexEnumExamplesTest : JavaMethodTestRunner() {
}

@Test
@Disabled("Some properties were not discovered at positions (from 0): [0]")
fun testCountNullColors() {
checkDiscoveredProperties(
ComplexEnumExamples::countNullColors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ internal class InvokeExampleTest : JavaMethodTestRunner() {


@Test
@Disabled("Expected exactly 3 executions, but 1 found. Tune coverage zone")
fun testConstraintsFromOutside() {
checkDiscoveredProperties(
InvokeExample::constraintsFromOutside,
Expand Down Expand Up @@ -103,6 +104,7 @@ internal class InvokeExampleTest : JavaMethodTestRunner() {
}

@Test
@Disabled("Expected exactly 3 executions, but 2 found. Tune coverage zone")
fun testExceptionInNestedMethod() {
checkDiscoveredPropertiesWithExceptions(
InvokeExample::exceptionInNestedMethod,
Expand All @@ -114,6 +116,7 @@ internal class InvokeExampleTest : JavaMethodTestRunner() {
}

@Test
@Disabled("Some properties were not discovered at positions (from 0): [1, 2, 3]. Tune coverage zone")
fun testFewNestedExceptions() {
checkDiscoveredPropertiesWithExceptions(
InvokeExample::fewNestedException,
Expand Down Expand Up @@ -162,6 +165,7 @@ internal class InvokeExampleTest : JavaMethodTestRunner() {
}

@Test
@Disabled("Expected exactly 3 executions, but 2 found. Tune coverage zone")
fun testChangeArrayWithAssignFromMethod() {
checkDiscoveredProperties(
InvokeExample::changeArrayWithAssignFromMethod,
Expand All @@ -176,6 +180,7 @@ internal class InvokeExampleTest : JavaMethodTestRunner() {
}

@Test
@Disabled("Some properties were not discovered at positions (from 0): [1]. Tune coverage zone")
fun testChangeArrayByMethod() {
checkDiscoveredProperties(
InvokeExample::changeArrayByMethod,
Expand All @@ -186,6 +191,7 @@ internal class InvokeExampleTest : JavaMethodTestRunner() {
}

@Test
@Disabled("Some properties were not discovered at positions (from 0): [3]. Tune coverage zone")
fun testArrayCopyExample() {
checkDiscoveredProperties(
InvokeExample::arrayCopyExample,
Expand Down
Loading

0 comments on commit e297948

Please sign in to comment.