diff --git a/gradle.properties b/gradle.properties index af70eca1b1..9956ddbb28 100644 --- a/gradle.properties +++ b/gradle.properties @@ -40,7 +40,6 @@ intellijPluginVersion=1.7.0 rdVersion=2022.2.1 # to enable - add -PincludeRiderInBuild=true in build CLI includeRiderInBuild=false -jacocoVersion=0.8.8 commonsLangVersion=3.11 commonsIoVersion=2.8.0 kotlinLoggingVersion=1.8.3 @@ -67,7 +66,6 @@ mavenPluginTestingVersion=3.3.0 mavenResolverApiVersion=1.8.0 sisuPlexusVersion=0.3.5 javaCppVersion=1.5.3 -jsoupVersion=1.7.2 djlApiVersion=0.17.0 pytorchNativeVersion=1.9.1 shadowJarVersion=7.1.2 @@ -75,16 +73,16 @@ openblasVersion=0.3.10-1.5.4 arpackNgVersion=3.7.0-1.5.4 # configuration for build server -org.gradle.daemon=false -org.gradle.parallel=false -org.gradle.jvmargs="-XX:MaxHeapSize=6144m" -kotlin.compiler.execution.strategy=in-process -org.gradle.caching=false +#org.gradle.daemon=false +#org.gradle.parallel=false +#org.gradle.jvmargs="-XX:MaxHeapSize=6144m" +#kotlin.compiler.execution.strategy=in-process +#org.gradle.caching=false # configuration for local compilation - much faster -#org.gradle.daemon=true -#kotlin.daemon.jvm.options=-Xmx4g -#org.gradle.parallel=true -#org.gradle.caching=true -#org.gradle.workers.max=8 -#org.gradle.jvmargs="-XX:MaxHeapSize=6144m" \ No newline at end of file +org.gradle.daemon=true +kotlin.daemon.jvm.options=-Xmx4g +org.gradle.parallel=true +org.gradle.caching=true +org.gradle.workers.max=8 +org.gradle.jvmargs="-XX:MaxHeapSize=6144m" \ No newline at end of file diff --git a/utbot-analytics-torch/build.gradle b/utbot-analytics-torch/build.gradle index b1d10f43d9..45d1fbc988 100644 --- a/utbot-analytics-torch/build.gradle +++ b/utbot-analytics-torch/build.gradle @@ -15,7 +15,6 @@ dependencies { testImplementation group: 'junit', name: 'junit', version: junit4Version implementation group: 'org.bytedeco', name: 'javacpp', version: javaCppVersion, classifier: "$classifier" - implementation group: 'org.jsoup', name: 'jsoup', version: jsoupVersion implementation "ai.djl:api:$djlApiVersion" implementation "ai.djl.pytorch:pytorch-engine:$djlApiVersion" diff --git a/utbot-cli-python/build.gradle b/utbot-cli-python/build.gradle index 9fd9d4fe24..468b074e19 100644 --- a/utbot-cli-python/build.gradle +++ b/utbot-cli-python/build.gradle @@ -29,7 +29,6 @@ dependencies { implementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junit5Version implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: log4j2Version implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: log4j2Version - implementation group: 'org.jacoco', name: 'org.jacoco.report', version: jacocoVersion //noinspection GroovyAssignabilityCheck fetchInstrumentationJar project(path: ':utbot-instrumentation', configuration:'instrumentationArchive') } diff --git a/utbot-cli/build.gradle b/utbot-cli/build.gradle index bf7b18b3c1..b0f3cf6224 100644 --- a/utbot-cli/build.gradle +++ b/utbot-cli/build.gradle @@ -29,7 +29,6 @@ dependencies { implementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junit5Version implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: log4j2Version implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: log4j2Version - implementation group: 'org.jacoco', name: 'org.jacoco.report', version: jacocoVersion fetchInstrumentationJar project(path: ':utbot-instrumentation', configuration: 'instrumentationArchive') } diff --git a/utbot-core/src/main/kotlin/org/utbot/common/StopWatch.kt b/utbot-core/src/main/kotlin/org/utbot/common/StopWatch.kt index 83ec7bb00c..1c355317f9 100644 --- a/utbot-core/src/main/kotlin/org/utbot/common/StopWatch.kt +++ b/utbot-core/src/main/kotlin/org/utbot/common/StopWatch.kt @@ -52,7 +52,7 @@ class StopWatch { } } - fun get(unit: TimeUnit) = lock.withLockInterruptibly { + fun get(unit: TimeUnit = TimeUnit.MILLISECONDS) = lock.withLockInterruptibly { unsafeUpdate() unit.convert(elapsedMillis, TimeUnit.MILLISECONDS) } diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt index 02bf1bc3f3..e3900a4982 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt @@ -277,7 +277,7 @@ object UtSettings : AbstractSettings(logger, defaultKeyForSettingsPath, defaultS /** * Timeout for specific concrete execution (in milliseconds). */ - var concreteExecutionTimeoutInInstrumentedProcess: Long by getLongProperty( + var concreteExecutionDefaultTimeoutInInstrumentedProcessMillis: Long by getLongProperty( DEFAULT_EXECUTION_TIMEOUT_IN_INSTRUMENTED_PROCESS_MS ) diff --git a/utbot-framework-test/build.gradle b/utbot-framework-test/build.gradle index b42815c1a7..2e02aa2f92 100644 --- a/utbot-framework-test/build.gradle +++ b/utbot-framework-test/build.gradle @@ -42,7 +42,6 @@ dependencies { implementation group: 'com.github.curious-odd-man', name: 'rgxgen', version: rgxgenVersion implementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: log4j2Version implementation group: 'io.github.microutils', name: 'kotlin-logging', version: kotlinLoggingVersion - implementation group: 'org.jacoco', name: 'org.jacoco.report', version: jacocoVersion implementation group: 'org.apache.commons', name: 'commons-text', version: apacheCommonsTextVersion // we need this for construction mocks from composite models implementation group: 'org.mockito', name: 'mockito-core', version: '4.2.0' diff --git a/utbot-framework/build.gradle b/utbot-framework/build.gradle index a46be75524..d1f5578f76 100644 --- a/utbot-framework/build.gradle +++ b/utbot-framework/build.gradle @@ -32,7 +32,6 @@ dependencies { implementation group: 'com.github.curious-odd-man', name: 'rgxgen', version: rgxgenVersion implementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: log4j2Version implementation group: 'io.github.microutils', name: 'kotlin-logging', version: kotlinLoggingVersion - implementation group: 'org.jacoco', name: 'org.jacoco.report', version: jacocoVersion implementation group: 'org.apache.commons', name: 'commons-text', version: apacheCommonsTextVersion // we need this for construction mocks from composite models implementation group: 'org.mockito', name: 'mockito-core', version: '4.2.0' diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt index 10a9138a8c..e3e587b40b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt @@ -48,6 +48,7 @@ import org.utbot.instrumentation.instrumentation.execution.UtExecutionInstrument import soot.jimple.Stmt import soot.tagkit.ParamNamesTag import java.lang.reflect.Method +import kotlin.math.min import kotlin.system.measureTimeMillis val logger = KotlinLogging.logger {} @@ -247,7 +248,7 @@ class UtBotSymbolicEngine( try { val concreteExecutionResult = - concreteExecutor.executeConcretely(methodUnderTest, stateBefore, instrumentation) + concreteExecutor.executeConcretely(methodUnderTest, stateBefore, instrumentation, UtSettings.concreteExecutionDefaultTimeoutInInstrumentedProcessMillis) if (concreteExecutionResult.violatesUtMockAssumption()) { logger.debug { "Generated test case violates the UtMock assumption: $concreteExecutionResult" } @@ -353,7 +354,14 @@ class UtBotSymbolicEngine( names, listOf(transform(ValueProvider.of(defaultValueProviders(defaultIdGenerator)))) ) { thisInstance, descr, values -> - if (controller.job?.isActive == false || System.currentTimeMillis() >= until) { + val diff = until - System.currentTimeMillis() + val thresholdMillisForFuzzingOperation = 0 // may be better use 10-20 millis as it might not be possible + // to concretely execute that values because request to instrumentation process involves + // 1. serializing/deserializing it with kryo + // 2. sending over rd + // 3. concrete execution itself + // 4. analyzing concrete result + if (controller.job?.isActive == false || diff <= thresholdMillisForFuzzingOperation) { logger.info { "Fuzzing overtime: $methodUnderTest" } logger.info { "Test created by fuzzer: $testEmittedByFuzzer" } return@runJavaFuzzing BaseFeedback(result = Trie.emptyNode(), control = Control.STOP) @@ -362,7 +370,8 @@ class UtBotSymbolicEngine( val initialEnvironmentModels = EnvironmentModels(thisInstance?.model, values.map { it.model }, mapOf()) val concreteExecutionResult: UtConcreteExecutionResult? = try { - concreteExecutor.executeConcretely(methodUnderTest, initialEnvironmentModels, listOf()) + val timeoutMillis = min(UtSettings.concreteExecutionDefaultTimeoutInInstrumentedProcessMillis, diff) + concreteExecutor.executeConcretely(methodUnderTest, initialEnvironmentModels, listOf(), timeoutMillis) } catch (e: CancellationException) { logger.debug { "Cancelled by timeout" }; null } catch (e: ConcreteExecutionFailureException) { @@ -508,7 +517,8 @@ class UtBotSymbolicEngine( val concreteExecutionResult = concreteExecutor.executeConcretely( methodUnderTest, stateBefore, - instrumentation + instrumentation, + UtSettings.concreteExecutionDefaultTimeoutInInstrumentedProcessMillis ) if (concreteExecutionResult.violatesUtMockAssumption()) { @@ -527,6 +537,10 @@ class UtBotSymbolicEngine( } } catch (e: ConcreteExecutionFailureException) { emitFailedConcreteExecutionResult(stateBefore, e) + } catch (e: CancellationException) { + logger.debug(e) { "Cancellation happened" } + } catch (e: Throwable) { + emit(UtError("Default concrete execution failed", e)); } } @@ -559,14 +573,16 @@ private fun ResolvedModels.constructStateForMethod(methodUnderTest: ExecutableId private suspend fun ConcreteExecutor.executeConcretely( methodUnderTest: ExecutableId, stateBefore: EnvironmentModels, - instrumentation: List + instrumentation: List, + timeoutInMillis: Long ): UtConcreteExecutionResult = executeAsync( methodUnderTest.classId.name, methodUnderTest.signature, arrayOf(), parameters = UtConcreteExecutionData( stateBefore, - instrumentation + instrumentation, + timeoutInMillis ) ).convertToAssemble(methodUnderTest.classId.packageName) diff --git a/utbot-framework/src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt b/utbot-framework/src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt index d3bf6bfbe4..ec8a869fc1 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt @@ -221,7 +221,8 @@ object UtBotJavaApi { arrayOf(), parameters = UtConcreteExecutionData( testInfo.initialState, - instrumentation = emptyList() + instrumentation = emptyList(), + UtSettings.concreteExecutionDefaultTimeoutInInstrumentedProcessMillis ) ).result } else { diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/domain/Domain.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/domain/Domain.kt index 98579b5de9..ffb2c074f4 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/domain/Domain.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/domain/Domain.kt @@ -584,7 +584,7 @@ enum class RuntimeExceptionTestsBehaviour( // Get is mandatory because of the initialization order of the inheritors. // Otherwise, in some cases we could get an incorrect value companion object : CodeGenerationSettingBox { - override val defaultItem: RuntimeExceptionTestsBehaviour get() = FAIL + override val defaultItem: RuntimeExceptionTestsBehaviour get() = PASS override val allItems: List = values().toList() } } diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/renderer/CgAbstractRenderer.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/renderer/CgAbstractRenderer.kt index c60e759cc9..c32ef82eb2 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/renderer/CgAbstractRenderer.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/renderer/CgAbstractRenderer.kt @@ -394,19 +394,14 @@ abstract class CgAbstractRenderer( val isBlockTooLarge = workaround(LONG_CODE_FRAGMENTS) { block.size > LARGE_CODE_BLOCK_SIZE } - if (isBlockTooLarge) { - print("/*") - println(" This block of code is ${block.size} lines long and could lead to compilation error") - } - - withIndent { - for (statement in block) { - statement.accept(this) + if (!isBlockTooLarge) { + withIndent { + for (statement in block) { + statement.accept(this) + } } } - if (isBlockTooLarge) println("*/") - print("}") if (printNextLine) println() @@ -959,6 +954,6 @@ abstract class CgAbstractRenderer( /** * @see [LONG_CODE_FRAGMENTS] */ - private const val LARGE_CODE_BLOCK_SIZE: Int = 1000 + private const val LARGE_CODE_BLOCK_SIZE: Int = 150 } } diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/minimization/Minimization.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/minimization/Minimization.kt index 4c2a46d1ca..e3d4d528bb 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/minimization/Minimization.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/minimization/Minimization.kt @@ -20,6 +20,7 @@ import org.utbot.framework.plugin.api.UtPrimitiveModel import org.utbot.framework.plugin.api.UtStatementModel import org.utbot.framework.plugin.api.UtSymbolicExecution import org.utbot.framework.plugin.api.UtVoidModel +import org.utbot.fuzzer.UtFuzzedExecution /** @@ -280,6 +281,6 @@ private fun Throwable.exceptionToInfo(): String = * See [https://github.com/UnitTestBot/UTBotJava/issues/1504] for more details. */ private fun UtExecution.getExecutionPriority(): Int = when (this) { - is UtSymbolicExecution -> 0 + is UtFuzzedExecution -> 0 else -> 1 } diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt index c86c96e274..f3e04bd7b6 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt @@ -180,7 +180,10 @@ open class TestCaseGenerator( } method2executions.getValue(method) += it } - is UtError -> method2errors.getValue(method).merge(it.description, 1, Int::plus) + is UtError -> { + method2errors.getValue(method).merge(it.description, 1, Int::plus) + logger.error(it.error) { "UtError occurred" } + } } } } catch (e: Exception) { diff --git a/utbot-instrumentation-tests/build.gradle b/utbot-instrumentation-tests/build.gradle index ba9c9c316b..d69bc23f8a 100644 --- a/utbot-instrumentation-tests/build.gradle +++ b/utbot-instrumentation-tests/build.gradle @@ -8,7 +8,6 @@ dependencies { testImplementation configurations.fetchInstrumentationJar testImplementation project(':utbot-sample') - testImplementation group: 'org.jacoco', name: 'org.jacoco.report', version: jacocoVersion implementation group: 'com.jetbrains.rd', name: 'rd-framework', version: rdVersion implementation group: 'com.jetbrains.rd', name: 'rd-core', version: rdVersion } diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentation.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentation.kt index 3ab2051f72..6847192aa3 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentation.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentation.kt @@ -4,17 +4,12 @@ import java.security.ProtectionDomain import java.util.IdentityHashMap import kotlin.reflect.jvm.javaMethod import org.utbot.framework.UtSettings +import org.utbot.framework.plugin.api.* import org.utbot.instrumentation.instrumentation.execution.constructors.ConstructOnlyUserClassesOrCachedObjectsStrategy import org.utbot.instrumentation.instrumentation.execution.constructors.UtModelConstructor import org.utbot.instrumentation.instrumentation.execution.mock.InstrumentationContext import org.utbot.instrumentation.instrumentation.execution.phases.PhasesController import org.utbot.instrumentation.instrumentation.execution.phases.start -import org.utbot.framework.plugin.api.Coverage -import org.utbot.framework.plugin.api.EnvironmentModels -import org.utbot.framework.plugin.api.FieldId -import org.utbot.framework.plugin.api.UtExecutionResult -import org.utbot.framework.plugin.api.UtInstrumentation -import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.singleExecutableId import org.utbot.instrumentation.instrumentation.ArgumentList import org.utbot.instrumentation.instrumentation.Instrumentation @@ -29,12 +24,12 @@ import org.utbot.instrumentation.instrumentation.mock.MockClassVisitor * @property [stateBefore] is necessary for construction of parameters of a concrete call. * @property [instrumentation] is necessary for mocking static methods and new instances. * @property [timeout] is timeout for specific concrete execution (in milliseconds). - * By default is initialized from [UtSettings.concreteExecutionTimeoutInInstrumentedProcess] + * By default is initialized from [UtSettings.concreteExecutionDefaultTimeoutInInstrumentedProcessMillis] */ data class UtConcreteExecutionData( val stateBefore: EnvironmentModels, val instrumentation: List, - val timeout: Long = UtSettings.concreteExecutionTimeoutInInstrumentedProcess + val timeout: Long ) class UtConcreteExecutionResult( @@ -88,14 +83,18 @@ object UtExecutionInstrumentation : Instrumentation { traceHandler, delegateInstrumentation ).computeConcreteExecutionResult { - // construction - val (params, statics, cache) = valueConstructionContext.start { - val params = constructParameters(stateBefore) - val statics = constructStatics(stateBefore) + var currentlyElapsed = 0L + val (params, statics, cache) = valueConstructionPhase.start { + val (result, elapsed) = invokeWithTimeoutWithUtContext(timeout) { + val params = constructParameters(stateBefore) + val statics = constructStatics(stateBefore) - mock(instrumentations) + mock(instrumentations) - Triple(params, statics, getCache()) + Triple(params, statics, getCache()) + } + currentlyElapsed += elapsed + result } // preparation @@ -108,33 +107,48 @@ object UtExecutionInstrumentation : Instrumentation { try { // invocation val concreteResult = invocationContext.start { - invoke(clazz, methodSignature, params.map { it.value }, timeout) + val (result, elapsed) = invokeWithTimeoutWithUtContext(timeout - currentlyElapsed) { + invoke(clazz, methodSignature, params.map { it.value }) + } + currentlyElapsed += elapsed + result } // statistics collection val coverage = statisticsCollectionContext.start { - getCoverage(clazz) + val (result, elapsed) = invokeWithTimeoutWithUtContext(timeout - currentlyElapsed) { + getCoverage(clazz) + } + currentlyElapsed += elapsed + result } // model construction val (executionResult, stateAfter) = modelConstructionContext.start { - configureConstructor { - this.cache = cache - strategy = ConstructOnlyUserClassesOrCachedObjectsStrategy(pathsToUserClasses, cache) + val (result, elapsed) = invokeWithTimeoutWithUtContext(timeout - currentlyElapsed) { + configureConstructor { + this.cache = cache + strategy = ConstructOnlyUserClassesOrCachedObjectsStrategy( + UtExecutionInstrumentation.pathsToUserClasses, + cache + ) + } + + val executionResult = convertToExecutionResult(concreteResult, returnClassId) + + val stateAfterParametersWithThis = constructParameters(params) + val stateAfterStatics = constructStatics(stateBefore, statics) + val (stateAfterThis, stateAfterParameters) = if (stateBefore.thisInstance == null) { + null to stateAfterParametersWithThis + } else { + stateAfterParametersWithThis.first() to stateAfterParametersWithThis.drop(1) + } + val stateAfter = EnvironmentModels(stateAfterThis, stateAfterParameters, stateAfterStatics) + + executionResult to stateAfter } - - val executionResult = convertToExecutionResult(concreteResult, returnClassId) - - val stateAfterParametersWithThis = constructParameters(params) - val stateAfterStatics = constructStatics(stateBefore, statics) - val (stateAfterThis, stateAfterParameters) = if (stateBefore.thisInstance == null) { - null to stateAfterParametersWithThis - } else { - stateAfterParametersWithThis.first() to stateAfterParametersWithThis.drop(1) - } - val stateAfter = EnvironmentModels(stateAfterThis, stateAfterParameters, stateAfterStatics) - - executionResult to stateAfter + currentlyElapsed += elapsed + result } UtConcreteExecutionResult( diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentationUtil.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentationUtil.kt new file mode 100644 index 0000000000..94c17e6d4c --- /dev/null +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentationUtil.kt @@ -0,0 +1,22 @@ +package org.utbot.instrumentation.instrumentation.execution + +import org.utbot.common.StopWatch +import org.utbot.common.ThreadBasedExecutor +import org.utbot.framework.plugin.api.TimeoutException +import org.utbot.framework.plugin.api.util.UtContext +import org.utbot.framework.plugin.api.util.utContext +import org.utbot.framework.plugin.api.util.withUtContext + +fun invokeWithTimeoutWithUtContext(timeoutMillis: Long, block: () -> T): Pair { + val stopWatch = StopWatch() + val context = UtContext(utContext.classLoader, stopWatch) + val result = ThreadBasedExecutor.threadLocal.invokeWithTimeout(timeoutMillis, stopWatch) { + withUtContext(context) { + block() + } + } ?: throw TimeoutException("Timeout $timeoutMillis elapsed") + + val elapsedMillis = stopWatch.get() + + return Pair(result.getOrThrow() as T, elapsedMillis) +} \ No newline at end of file diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/InvocationContext.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/InvocationContext.kt index 5c301e96e0..9a68a44a3b 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/InvocationContext.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/InvocationContext.kt @@ -1,42 +1,32 @@ package org.utbot.instrumentation.instrumentation.execution.phases -import org.utbot.common.StopWatch -import org.utbot.common.ThreadBasedExecutor +import org.utbot.framework.plugin.api.Coverage +import org.utbot.framework.plugin.api.MissingState import org.utbot.framework.plugin.api.TimeoutException -import org.utbot.framework.plugin.api.util.UtContext -import org.utbot.framework.plugin.api.util.utContext -import org.utbot.framework.plugin.api.util.withUtContext +import org.utbot.framework.plugin.api.UtTimeoutException import org.utbot.instrumentation.instrumentation.Instrumentation +import org.utbot.instrumentation.instrumentation.execution.UtConcreteExecutionResult -class InvocationPhaseError(cause: Throwable) : PhaseError( - message = "Error during user's code invocation phase", - cause -) /** * This phase is about invoking user's code using [delegateInstrumentation]. */ class InvocationContext( private val delegateInstrumentation: Instrumentation> -) : PhaseContext { +) : ExecutionPhase { + + override fun wrapError(e: Throwable): ExecutionPhaseException { + val message = this.javaClass.simpleName + return when(e) { + is TimeoutException -> ExecutionPhaseStop(message, UtConcreteExecutionResult(MissingState, UtTimeoutException(e), Coverage())) + else -> ExecutionPhaseError(message, e) + } + } - override fun wrapError(error: Throwable): InvocationPhaseError = - InvocationPhaseError(error) fun invoke( clazz: Class<*>, methodSignature: String, params: List, - timeout: Long, - ): Result<*> { - val stopWatch = StopWatch() - val context = UtContext(utContext.classLoader, stopWatch) - val concreteResult = ThreadBasedExecutor.threadLocal.invokeWithTimeout(timeout, stopWatch) { - withUtContext(context) { - delegateInstrumentation.invoke(clazz, methodSignature, params) - } - }?.getOrThrow() as? Result<*> ?: Result.failure(TimeoutException("Timeout $timeout elapsed")) - return concreteResult - } - + ): Result<*> = delegateInstrumentation.invoke(clazz, methodSignature, params) } \ No newline at end of file diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/ModelConstructionContext.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/ModelConstructionContext.kt index 12d57ed0be..6d4e8f836e 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/ModelConstructionContext.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/ModelConstructionContext.kt @@ -3,42 +3,30 @@ package org.utbot.instrumentation.instrumentation.execution.phases import java.security.AccessControlException import java.util.IdentityHashMap import org.utbot.common.withAccessibility +import org.utbot.framework.plugin.api.* import org.utbot.instrumentation.instrumentation.execution.constructors.UtCompositeModelStrategy import org.utbot.instrumentation.instrumentation.execution.constructors.UtModelConstructor -import org.utbot.framework.plugin.api.ClassId -import org.utbot.framework.plugin.api.EnvironmentModels -import org.utbot.framework.plugin.api.FieldId -import org.utbot.framework.plugin.api.TimeoutException -import org.utbot.framework.plugin.api.UtConcreteValue -import org.utbot.framework.plugin.api.UtExecutionFailure -import org.utbot.framework.plugin.api.UtExecutionResult -import org.utbot.framework.plugin.api.UtExecutionSuccess -import org.utbot.framework.plugin.api.UtExplicitlyThrownException -import org.utbot.framework.plugin.api.UtImplicitlyThrownException -import org.utbot.framework.plugin.api.UtModel -import org.utbot.framework.plugin.api.UtSandboxFailure -import org.utbot.framework.plugin.api.UtStreamConsumingFailure -import org.utbot.framework.plugin.api.UtTimeoutException import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.jField import org.utbot.framework.plugin.api.visible.UtStreamConsumingException import org.utbot.instrumentation.instrumentation.et.ExplicitThrowInstruction import org.utbot.instrumentation.instrumentation.et.TraceHandler - -class ModelConstructionPhaseError(cause: Throwable) : PhaseError( - message = "Error during model construction phase", - cause -) +import org.utbot.instrumentation.instrumentation.execution.UtConcreteExecutionResult /** * This phase of model construction from concrete values. */ class ModelConstructionContext( private val traceHandler: TraceHandler -) : PhaseContext { +) : ExecutionPhase { - override fun wrapError(error: Throwable): ModelConstructionPhaseError = - ModelConstructionPhaseError(error) + override fun wrapError(e: Throwable): ExecutionPhaseException { + val message = this.javaClass.simpleName + return when(e) { + is TimeoutException -> ExecutionPhaseStop(message, UtConcreteExecutionResult(MissingState, UtTimeoutException(e), Coverage())) + else -> ExecutionPhaseError(message, e) + } + } private lateinit var constructor: UtModelConstructor diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/PhaseContext.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/PhaseContext.kt index d1beaaa21b..60a4424b9a 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/PhaseContext.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/PhaseContext.kt @@ -1,13 +1,33 @@ package org.utbot.instrumentation.instrumentation.execution.phases -abstract class PhaseError(message: String, override val cause: Throwable) : Exception(message) -interface PhaseContext { - fun wrapError(error: Throwable): E +import com.jetbrains.rd.util.debug +import com.jetbrains.rd.util.getLogger +import org.utbot.instrumentation.instrumentation.execution.UtConcreteExecutionResult +import org.utbot.rd.logMeasure + +val logger = getLogger("Executionphase") + +abstract class ExecutionPhaseException(override val message: String): Exception() + +// InstrumentationProcessError +class ExecutionPhaseError(phase: String, override val cause: Throwable) : ExecutionPhaseException(phase) + +// Ok +class ExecutionPhaseStop(phase: String, val result: UtConcreteExecutionResult): ExecutionPhaseException(phase ) + +interface ExecutionPhase { + fun wrapError(e: Throwable): ExecutionPhaseException } -inline fun > T.start(block: T.() -> R): R = +fun T.start(block: T.() -> R): R = try { - block() - } catch (e: Throwable) { - throw wrapError(e) + logger.logMeasure(this.javaClass.simpleName) { + this.block() + } + } + catch (e: ExecutionPhaseStop) { + throw e + } + catch (e: Throwable) { + throw this.wrapError(e) } diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/PhasesController.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/PhasesController.kt index 58617a3a61..c8980c131b 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/PhasesController.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/PhasesController.kt @@ -1,14 +1,14 @@ package org.utbot.instrumentation.instrumentation.execution.phases -import java.io.Closeable -import java.security.AccessControlException -import org.utbot.instrumentation.instrumentation.execution.UtConcreteExecutionResult -import org.utbot.instrumentation.instrumentation.execution.mock.InstrumentationContext import org.utbot.framework.plugin.api.Coverage import org.utbot.framework.plugin.api.MissingState import org.utbot.framework.plugin.api.UtSandboxFailure import org.utbot.instrumentation.instrumentation.Instrumentation import org.utbot.instrumentation.instrumentation.et.TraceHandler +import org.utbot.instrumentation.instrumentation.execution.UtConcreteExecutionResult +import org.utbot.instrumentation.instrumentation.execution.mock.InstrumentationContext +import java.io.Closeable +import java.security.AccessControlException class PhasesController( instrumentationContext: InstrumentationContext, @@ -16,7 +16,7 @@ class PhasesController( delegateInstrumentation: Instrumentation>, ) : Closeable { - val valueConstructionContext = ValueConstructionContext(instrumentationContext) + val valueConstructionPhase = ValueConstructionPhase(instrumentationContext) val preparationContext = PreparationContext(traceHandler) @@ -31,8 +31,12 @@ class PhasesController( inline fun computeConcreteExecutionResult(block: PhasesController.() -> UtConcreteExecutionResult): UtConcreteExecutionResult { return use { try { - block() - } catch (e: PhaseError) { + this.block() + } + catch (e: ExecutionPhaseStop) { + return e.result + } + catch (e: ExecutionPhaseError) { if (e.cause.cause is AccessControlException) { return@use UtConcreteExecutionResult( MissingState, @@ -47,7 +51,7 @@ class PhasesController( } override fun close() { - valueConstructionContext.close() + valueConstructionPhase.close() } } \ No newline at end of file diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/PostprocessingContext.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/PostprocessingContext.kt index 9ddd7f318d..c2475c855c 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/PostprocessingContext.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/PostprocessingContext.kt @@ -4,18 +4,13 @@ import org.utbot.common.withAccessibility import org.utbot.framework.plugin.api.FieldId import org.utbot.framework.plugin.api.util.jField -class PostprocessingPhaseError(cause: Throwable) : PhaseError( - message = "Error during postprocessing phase", - cause -) /** * The responsibility of this phase is resetting environment to the initial state. */ -class PostprocessingContext : PhaseContext { +class PostprocessingContext : ExecutionPhase { - override fun wrapError(error: Throwable): PostprocessingPhaseError = - PostprocessingPhaseError(error) + override fun wrapError(e: Throwable): ExecutionPhaseException = ExecutionPhaseError(this.javaClass.simpleName, e) fun resetStaticFields(staticFields: Map) { staticFields.forEach { (fieldId, value) -> diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/PreparationContext.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/PreparationContext.kt index 78b90bef1a..7408449f82 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/PreparationContext.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/PreparationContext.kt @@ -6,20 +6,16 @@ import org.utbot.framework.plugin.api.UtConcreteValue import org.utbot.framework.plugin.api.util.jField import org.utbot.instrumentation.instrumentation.et.TraceHandler -class PreparationPhaseError(cause: Throwable) : PhaseError( - message = "Error during environment preparation phase", - cause -) /** * The responsibility of this phase is environment preparation before execution. */ class PreparationContext( private val traceHandler: TraceHandler -) : PhaseContext { +) : ExecutionPhase { - override fun wrapError(error: Throwable): PreparationPhaseError = - PreparationPhaseError(error) + override fun wrapError(e: Throwable): ExecutionPhaseException = + ExecutionPhaseError(this.javaClass.simpleName, e) fun setStaticFields(staticFieldsValues: Map>): Map { val savedStaticFields = mutableMapOf() diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/StatisticsCollectionContext.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/StatisticsCollectionContext.kt index 797f2a2f7a..e41f8601f6 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/StatisticsCollectionContext.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/StatisticsCollectionContext.kt @@ -1,25 +1,25 @@ package org.utbot.instrumentation.instrumentation.execution.phases import org.objectweb.asm.Type -import org.utbot.framework.plugin.api.Coverage -import org.utbot.framework.plugin.api.Instruction +import org.utbot.framework.plugin.api.* import org.utbot.instrumentation.instrumentation.et.EtInstruction import org.utbot.instrumentation.instrumentation.et.TraceHandler - -class StatisticsCollectionPhaseError(cause: Throwable) : PhaseError( - message = "Error during statistics collection phase", - cause -) +import org.utbot.instrumentation.instrumentation.execution.UtConcreteExecutionResult /** * This phase is about collection statistics such as coverage. */ class StatisticsCollectionContext( private val traceHandler: TraceHandler -) : PhaseContext { +) : ExecutionPhase { - override fun wrapError(error: Throwable): StatisticsCollectionPhaseError = - StatisticsCollectionPhaseError(error) + override fun wrapError(e: Throwable): ExecutionPhaseException { + val message = this.javaClass.simpleName + return when(e) { + is TimeoutException -> ExecutionPhaseStop(message, UtConcreteExecutionResult(MissingState, UtTimeoutException(e), Coverage())) + else -> ExecutionPhaseError(message, e) + } + } fun getCoverage(clazz: Class<*>): Coverage { return traceHandler diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/ValueConstructionContext.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/ValueConstructionPhase.kt similarity index 64% rename from utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/ValueConstructionContext.kt rename to utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/ValueConstructionPhase.kt index aaa5732f25..17edecf507 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/ValueConstructionContext.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/ValueConstructionPhase.kt @@ -1,32 +1,31 @@ package org.utbot.instrumentation.instrumentation.execution.phases +import org.utbot.framework.plugin.api.* import java.io.Closeable import java.util.IdentityHashMap import org.utbot.instrumentation.instrumentation.execution.constructors.MockValueConstructor import org.utbot.instrumentation.instrumentation.execution.mock.InstrumentationContext -import org.utbot.framework.plugin.api.EnvironmentModels -import org.utbot.framework.plugin.api.FieldId -import org.utbot.framework.plugin.api.UtConcreteValue -import org.utbot.framework.plugin.api.UtInstrumentation -import org.utbot.framework.plugin.api.UtModel -import org.utbot.framework.plugin.api.UtNewInstanceInstrumentation -import org.utbot.framework.plugin.api.UtStaticMethodInstrumentation import org.utbot.framework.plugin.api.util.isInaccessibleViaReflection +import org.utbot.instrumentation.instrumentation.execution.UtConcreteExecutionResult -class ValueConstructionPhaseError(cause: Throwable) : PhaseError( - message = "Error during phase of constructing values from models", - cause -) +typealias ConstructedParameters = List> +typealias ConstructedStatics = Map> +typealias ConstructedCache = IdentityHashMap /** * This phase of values instantiation from given models. */ -class ValueConstructionContext( +class ValueConstructionPhase( instrumentationContext: InstrumentationContext -) : PhaseContext, Closeable { +) : ExecutionPhase, Closeable { - override fun wrapError(error: Throwable): ValueConstructionPhaseError = - ValueConstructionPhaseError(error) + override fun wrapError(e: Throwable): ExecutionPhaseException { + val message = this.javaClass.simpleName + return when(e) { + is TimeoutException -> ExecutionPhaseStop(message, UtConcreteExecutionResult(MissingState, UtTimeoutException(e), Coverage())) + else -> ExecutionPhaseError(message, e) + } + } private val constructor = MockValueConstructor(instrumentationContext) @@ -34,12 +33,12 @@ class ValueConstructionContext( return constructor.objectToModelCache } - fun constructParameters(state: EnvironmentModels): List> { + fun constructParameters(state: EnvironmentModels): ConstructedParameters { val parametersModels = listOfNotNull(state.thisInstance) + state.parameters return constructor.constructMethodParameters(parametersModels) } - fun constructStatics(state: EnvironmentModels): Map> = + fun constructStatics(state: EnvironmentModels): ConstructedStatics = constructor.constructStatics( state.statics.filterKeys { !it.isInaccessibleViaReflection } ) @@ -62,5 +61,4 @@ class ValueConstructionContext( override fun close() { constructor.close() } - } diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt index d6012247fe..44689af7ce 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt @@ -139,7 +139,7 @@ object UtTestsDialogProcessor { return } - UtSettings.concreteExecutionTimeoutInInstrumentedProcess = model.hangingTestsTimeout.timeoutMs + UtSettings.concreteExecutionDefaultTimeoutInInstrumentedProcessMillis = model.hangingTestsTimeout.timeoutMs UtSettings.useCustomJavaDocTags = model.commentStyle == JavaDocCommentStyle.CUSTOM_JAVADOC_TAGS UtSettings.summaryGenerationType = model.summariesGenerationType diff --git a/utbot-junit-contest/build.gradle b/utbot-junit-contest/build.gradle index dd40d660f7..ee5b6f2179 100644 --- a/utbot-junit-contest/build.gradle +++ b/utbot-junit-contest/build.gradle @@ -1,7 +1,7 @@ plugins { id 'org.jetbrains.kotlin.plugin.serialization' version '1.7.20' } -apply plugin: 'jacoco' +//apply plugin: 'jacoco' configurations { fetchInstrumentationJar @@ -42,14 +42,14 @@ test { // set JVM arguments for the test JVM(s) jvmArgs '-XX:MaxHeapSize=3072m' - finalizedBy jacocoTestReport +// finalizedBy jacocoTestReport } -jacocoTestReport { - reports { - html.enabled = true - } -} +//jacocoTestReport { +// reports { +// html.enabled = true +// } +//} dependencies { implementation project(":utbot-framework") @@ -60,7 +60,6 @@ dependencies { } implementation group: 'org.apache.commons', name: 'commons-exec', version: '1.2' implementation group: 'io.github.microutils', name: 'kotlin-logging', version: kotlinLoggingVersion - implementation group: 'org.jsoup', name: 'jsoup', version: '1.6.2' implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1' // need for tests implementation group: 'org.mockito', name: 'mockito-core', version: '4.2.0' diff --git a/utbot-junit-contest/runtool b/utbot-junit-contest/runtool index 43e3becd6c..b191e8a6fc 100644 --- a/utbot-junit-contest/runtool +++ b/utbot-junit-contest/runtool @@ -1,10 +1,10 @@ #!/bin/bash # switch to environment JVM as needed -JAVA_HOME=/usr +JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 -APACHE_EXECS_LIB=lib/org/apache/commons/commons-exec/1.2/commons-exec-1.2.jar -TOOL=lib/runtool-1.0.0.jar +TOOL=lib/utbot-junit-contest-1.0.jar +export UTBOT_EXTRA_PARAMS=-Xmx4g export JAVA_HOME=$JAVA_HOME -$JAVA_HOME/bin/java -cp $TOOL:$APACHE_EXECS_LIB sbst.runtool.Main +$JAVA_HOME/bin/java -cp $TOOL sbst.runtool.Main diff --git a/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt index 41cb8aac64..00e99c9967 100644 --- a/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt +++ b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt @@ -403,7 +403,7 @@ fun runGeneration( val testSets = testsByMethod.map { (method, executions) -> UtMethodTestSet(method, minimizeExecutions(executions), jimpleBody(method)) - .summarize(cut.classfileDir.toPath()) + .summarize(sourceFile = null, cut.classfileDir.toPath()) } logger.info().bracket("Flushing tests for [${cut.simpleName}] on disk") { diff --git a/utbot-junit-contest/src/main/kotlin/org/utbot/contest/JacocoReportFilter.kt b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/JacocoReportFilter.kt index d0c5100873..85dcf83aa4 100644 --- a/utbot-junit-contest/src/main/kotlin/org/utbot/contest/JacocoReportFilter.kt +++ b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/JacocoReportFilter.kt @@ -1,63 +1,63 @@ package org.utbot.contest -import java.nio.charset.Charset -import java.nio.file.Files -import java.nio.file.Path -import java.nio.file.Paths -import kotlin.streams.asSequence -import org.jsoup.Jsoup -import org.jsoup.nodes.Element -import org.jsoup.nodes.Node - -fun main(args: Array) { - val originalReportPath: Path - val classFiltersFolder: Path - - if (args.isEmpty()) { - println("Using default parameters to start filtering") - originalReportPath = Paths.get("utbot-junit-contest/build/reports/jacoco/test/html/index.html").toAbsolutePath() - classFiltersFolder = Paths.get("utbot-junit-contest/src/main/resources/classes").toAbsolutePath() - } else { - println("Command line arguments being passed: ${args.toText()}") - originalReportPath = Paths.get(args[0]) - classFiltersFolder = Paths.get(args[1]) - } - - val originalReport = Jsoup.parse(originalReportPath.toFile(), "UTF-8") - val packages = packages(classFiltersFolder.toAbsolutePath()) - removeIrrelevantPackages(originalReport, packages) - val filteredReportPath = Paths.get(originalReportPath.parent.toString(), "index_filtered.html") - println("Saving filtered report to ${filteredReportPath.toAbsolutePath()}") - Files.write(filteredReportPath, originalReport.html().toByteArray(Charset.defaultCharset())) -} - -fun packages(path: Path) = Files.walk(path) - .asSequence() - .filter(Files::isRegularFile) - .flatMap { Files.readAllLines(it) } - .mapTo(mutableSetOf()) { it.substringBeforeLast(".") } - -private fun removeIrrelevantPackages(node: Node, packages: Set) { - var i = 0 - while (i < node.childNodes().size) { - val child = node.childNode(i) - if (child.toBeRemoved(packages)) { - child.remove() - } else { - removeIrrelevantPackages(child, packages) - i++ - } - } -} - -fun Node.toBeRemoved(packages: Set): Boolean { - if (this.nodeName() == "tr") { - val href = (this as Element).select("a[href]").attr("href") - if (href.endsWith("index.html") - && href.substringBeforeLast("/") !in packages - ) { - return true - } - } - return false -} \ No newline at end of file +//import java.nio.charset.Charset +//import java.nio.file.Files +//import java.nio.file.Path +//import java.nio.file.Paths +//import kotlin.streams.asSequence +//import org.jsoup.Jsoup +//import org.jsoup.nodes.Element +//import org.jsoup.nodes.Node +// +//fun main(args: Array) { +// val originalReportPath: Path +// val classFiltersFolder: Path +// +// if (args.isEmpty()) { +// println("Using default parameters to start filtering") +// originalReportPath = Paths.get("utbot-junit-contest/build/reports/jacoco/test/html/index.html").toAbsolutePath() +// classFiltersFolder = Paths.get("utbot-junit-contest/src/main/resources/classes").toAbsolutePath() +// } else { +// println("Command line arguments being passed: ${args.toText()}") +// originalReportPath = Paths.get(args[0]) +// classFiltersFolder = Paths.get(args[1]) +// } +// +// val originalReport = Jsoup.parse(originalReportPath.toFile(), "UTF-8") +// val packages = packages(classFiltersFolder.toAbsolutePath()) +// removeIrrelevantPackages(originalReport, packages) +// val filteredReportPath = Paths.get(originalReportPath.parent.toString(), "index_filtered.html") +// println("Saving filtered report to ${filteredReportPath.toAbsolutePath()}") +// Files.write(filteredReportPath, originalReport.html().toByteArray(Charset.defaultCharset())) +//} +// +//fun packages(path: Path) = Files.walk(path) +// .asSequence() +// .filter(Files::isRegularFile) +// .flatMap { Files.readAllLines(it) } +// .mapTo(mutableSetOf()) { it.substringBeforeLast(".") } +// +//private fun removeIrrelevantPackages(node: Node, packages: Set) { +// var i = 0 +// while (i < node.childNodes().size) { +// val child = node.childNode(i) +// if (child.toBeRemoved(packages)) { +// child.remove() +// } else { +// removeIrrelevantPackages(child, packages) +// i++ +// } +// } +//} +// +//fun Node.toBeRemoved(packages: Set): Boolean { +// if (this.nodeName() == "tr") { +// val href = (this as Element).select("a[href]").attr("href") +// if (href.endsWith("index.html") +// && href.substringBeforeLast("/") !in packages +// ) { +// return true +// } +// } +// return false +//} \ No newline at end of file diff --git a/utbot-junit-contest/src/main/kotlin/org/utbot/runtool/UtBotTool2.kt b/utbot-junit-contest/src/main/kotlin/org/utbot/runtool/UtBotTool2.kt index d28051b2c4..a52b10ec37 100644 --- a/utbot-junit-contest/src/main/kotlin/org/utbot/runtool/UtBotTool2.kt +++ b/utbot-junit-contest/src/main/kotlin/org/utbot/runtool/UtBotTool2.kt @@ -11,7 +11,7 @@ import sbst.runtool.ITestingTool class UtBotTool2 : ITestingTool { override fun getExtraClassPath(): List { - return mutableListOf() + return mutableListOf(File("lib", "mockito-core-4.2.0.jar")) } lateinit var sootClasspathString: String diff --git a/utbot-rd/src/main/kotlin/org/utbot/rd/UtRdUtil.kt b/utbot-rd/src/main/kotlin/org/utbot/rd/UtRdUtil.kt index 1bfa0ca51d..f908962ec4 100644 --- a/utbot-rd/src/main/kotlin/org/utbot/rd/UtRdUtil.kt +++ b/utbot-rd/src/main/kotlin/org/utbot/rd/UtRdUtil.kt @@ -4,6 +4,9 @@ import com.jetbrains.rd.framework.* import com.jetbrains.rd.framework.impl.RdCall import com.jetbrains.rd.framework.util.NetUtils import com.jetbrains.rd.framework.util.synchronizeWith +import com.jetbrains.rd.util.Logger +import com.jetbrains.rd.util.debug +import com.jetbrains.rd.util.info import com.jetbrains.rd.util.lifetime.Lifetime import com.jetbrains.rd.util.lifetime.LifetimeDefinition import com.jetbrains.rd.util.lifetime.throwIfNotAlive @@ -123,4 +126,19 @@ suspend fun startUtProcessWithRdServer( it ) } +} + +inline fun Logger.logMeasure(tag: String = "", block: () -> T): T { + val start = System.currentTimeMillis() + this.debug { "started evaluating $tag" } + try { + return block() + } + catch (e: Throwable) { + this.debug { "exception during evaluating $tag: ${e.printStackTrace()}" } + throw e + } + finally { + this.debug { "evaluating $tag took ${System.currentTimeMillis() - start} ms" } + } } \ No newline at end of file diff --git a/utbot-rd/src/main/kotlin/org/utbot/rd/generated/SynchronizationModelRoot.Generated.kt b/utbot-rd/src/main/kotlin/org/utbot/rd/generated/SynchronizationModelRoot.Generated.kt deleted file mode 100644 index 32b75c35ed..0000000000 --- a/utbot-rd/src/main/kotlin/org/utbot/rd/generated/SynchronizationModelRoot.Generated.kt +++ /dev/null @@ -1,58 +0,0 @@ -@file:Suppress("EXPERIMENTAL_API_USAGE","EXPERIMENTAL_UNSIGNED_LITERALS","PackageDirectoryMismatch","UnusedImport","unused","LocalVariableName","CanBeVal","PropertyName","EnumEntryName","ClassName","ObjectPropertyName","UnnecessaryVariable","SpellCheckingInspection") -package org.utbot.rd.generated - -import com.jetbrains.rd.framework.* -import com.jetbrains.rd.framework.base.* -import com.jetbrains.rd.framework.impl.* - -import com.jetbrains.rd.util.lifetime.* -import com.jetbrains.rd.util.reactive.* -import com.jetbrains.rd.util.string.* -import com.jetbrains.rd.util.* -import kotlin.reflect.KClass -import kotlin.jvm.JvmStatic - - - -/** - * #### Generated from [SynchronizationModel.kt:5] - */ -class SynchronizationModelRoot private constructor( -) : RdExtBase() { - //companion - - companion object : ISerializersOwner { - - override fun registerSerializersCore(serializers: ISerializers) { - SynchronizationModelRoot.register(serializers) - SynchronizationModel.register(serializers) - } - - - - - - const val serializationHash = -1304011640135373779L - - } - override val serializersOwner: ISerializersOwner get() = SynchronizationModelRoot - override val serializationHash: Long get() = SynchronizationModelRoot.serializationHash - - //fields - //methods - //initializer - //secondary constructor - //equals trait - //hash code trait - //pretty print - override fun print(printer: PrettyPrinter) { - printer.println("SynchronizationModelRoot (") - printer.print(")") - } - //deepClone - override fun deepClone(): SynchronizationModelRoot { - return SynchronizationModelRoot( - ) - } - //contexts -} diff --git a/utbot-testing/build.gradle b/utbot-testing/build.gradle index 50c4a6f432..bebea582d0 100644 --- a/utbot-testing/build.gradle +++ b/utbot-testing/build.gradle @@ -26,7 +26,6 @@ dependencies { implementation group: 'com.github.curious-odd-man', name: 'rgxgen', version: rgxgenVersion implementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: log4j2Version implementation group: 'io.github.microutils', name: 'kotlin-logging', version: kotlinLoggingVersion - implementation group: 'org.jacoco', name: 'org.jacoco.report', version: jacocoVersion implementation group: 'org.apache.commons', name: 'commons-text', version: apacheCommonsTextVersion // we need this for construction mocks from composite models implementation group: 'org.mockito', name: 'mockito-core', version: '4.2.0'