diff --git a/gradle.properties b/gradle.properties index 3eb5dbb40a..2cba260598 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,8 @@ junit4_platform_version=1.9.0 mockito_version=3.5.13 z3_version=4.8.9.1 z3_java_api_version=4.8.9 -soot_commit_hash=c6c78d9 +soot_commit_hash=1f34746 +# previous soot_commit_hash=c6c78d9 kotlin_version=1.7.10 log4j2_version=2.13.3 coroutines_version=1.6.3 diff --git a/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt b/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt index 1d07875951..83aa105b0f 100644 --- a/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt +++ b/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt @@ -30,6 +30,7 @@ import org.utbot.framework.plugin.api.MockStrategyApi import org.utbot.framework.plugin.api.TestCaseGenerator import org.utbot.framework.plugin.api.TreatOverflowAsError import org.utbot.framework.plugin.api.UtMethodTestSet +import org.utbot.framework.plugin.services.JdkInfoDefaultProvider import org.utbot.summary.summarize import java.io.File import java.net.URLClassLoader @@ -46,7 +47,7 @@ private val logger = KotlinLogging.logger {} abstract class GenerateTestsAbstractCommand(name: String, help: String) : CliktCommand(name = name, help = help) { - abstract val classPath:String? + abstract val classPath: String? private val mockStrategy by option("-m", "--mock-strategy", help = "Defines the mock strategy") .choice( @@ -179,7 +180,11 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) : } } - protected fun generateTest(classUnderTest: ClassId, testClassname: String, testSets: List): String = + protected fun generateTest( + classUnderTest: ClassId, + testClassname: String, + testSets: List + ): String = initializeCodeGenerator( testFramework, classUnderTest @@ -191,7 +196,12 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) : // TODO: SAT-1566 Set UtSettings parameters. UtSettings.treatOverflowAsError = treatOverflowAsError == TreatOverflowAsError.AS_ERROR - return TestCaseGenerator(workingDirectory, classPathNormalized, System.getProperty("java.class.path")) + return TestCaseGenerator( + workingDirectory, + classPathNormalized, + System.getProperty("java.class.path"), + JdkInfoDefaultProvider().info + ) } private fun initializeCodeGenerator(testFramework: String, classUnderTest: ClassId): CodeGenerator { diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/services/JdkInfoService.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/services/JdkInfoService.kt index ca4a3ddb3a..fd4d27bd9b 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/services/JdkInfoService.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/services/JdkInfoService.kt @@ -5,7 +5,6 @@ import java.nio.file.Paths data class JdkInfo( val path: Path, - @Suppress("unused") val version: Int ) @@ -26,6 +25,9 @@ interface JdkInfoProvider { val info: JdkInfo } +/** + * Gets [JdkInfo] from the current process. + */ open class JdkInfoDefaultProvider : JdkInfoProvider { override val info: JdkInfo = JdkInfo(Paths.get(System.getProperty("java.home")), fetchJavaVersion(System.getProperty("java.version"))) diff --git a/utbot-framework-test/src/test/java/org/utbot/examples/manual/UtBotJavaApiTest.java b/utbot-framework-test/src/test/java/org/utbot/examples/manual/UtBotJavaApiTest.java index a054a8b1ea..3115f37fca 100644 --- a/utbot-framework-test/src/test/java/org/utbot/examples/manual/UtBotJavaApiTest.java +++ b/utbot-framework-test/src/test/java/org/utbot/examples/manual/UtBotJavaApiTest.java @@ -25,6 +25,7 @@ import org.utbot.framework.codegen.MockitoStaticMocking; import org.utbot.framework.plugin.api.*; import org.utbot.framework.plugin.api.util.UtContext; +import org.utbot.framework.plugin.services.JdkInfoDefaultProvider; import org.utbot.framework.util.Snippet; import org.utbot.framework.util.SootUtils; @@ -1226,7 +1227,7 @@ public void testOnObjectWithArrayOfComplexArrays() { @Test public void testFuzzingSimple() { - SootUtils.INSTANCE.runSoot(StringSwitchExample.class, false); + SootUtils.INSTANCE.runSoot(StringSwitchExample.class, false, new JdkInfoDefaultProvider().getInfo()); UtBotJavaApi.setStopConcreteExecutorOnExit(false); String classpath = getClassPath(StringSwitchExample.class); diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/bytecode/versions/SootTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/bytecode/versions/SootTest.kt new file mode 100644 index 0000000000..e988274ce0 --- /dev/null +++ b/utbot-framework-test/src/test/kotlin/org/utbot/bytecode/versions/SootTest.kt @@ -0,0 +1,69 @@ +package org.utbot.bytecode.versions + +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertNotNull +import org.junit.jupiter.api.Assertions.assertNull +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test +import org.utbot.examples.objects.SimpleDataClass +import org.utbot.framework.util.SootUtils.runSoot +import soot.Scene + +@Suppress("UNREACHABLE_CODE") +@Disabled("TODO: https://github.com/UnitTestBot/UTBotJava/issues/891") +class SootTest { + @Test + fun `no method isBlank in JDK 8`() { + runSoot( + SimpleDataClass::class.java, + forceReload = true, + TODO("Get JDK 8") + ) + + val stringClass = Scene.v().getSootClass("java.lang.String") + assertFalse(stringClass.isPhantomClass) + + val isBlankMethod = stringClass.getMethodByNameUnsafe("isBlank") // no such method in JDK 8 + assertNull(isBlankMethod) + } + + @Test + fun `method isBlank exists in JDK 11`() { + runSoot( + SimpleDataClass::class.java, + forceReload = true, + TODO("Get JDK 11") + ) + + val stringClass = Scene.v().getSootClass("java.lang.String") + assertFalse(stringClass.isPhantomClass) + + val isBlankMethod = stringClass.getMethodByNameUnsafe("isBlank") // there is such method in JDK 11 + assertNotNull(isBlankMethod) + } + + @Test + fun `no records in JDK 11`() { + runSoot( + SimpleDataClass::class.java, + forceReload = true, + TODO("Get JDK 11") + ) + + val stringClass = Scene.v().getSootClass("java.lang.Record") // must not exist in JDK 11 + assertTrue(stringClass.isPhantomClass) + } + + @Test + fun `records exists in JDK 17`() { + runSoot( + SimpleDataClass::class.java, + forceReload = true, + TODO("Get JDK 17") + ) + + val stringClass = Scene.v().getSootClass("java.lang.Record") // must exist in JDK 17 + assertFalse(stringClass.isPhantomClass) + } +} \ No newline at end of file diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/framework/assemble/AssembleModelGeneratorTests.kt b/utbot-framework-test/src/test/kotlin/org/utbot/framework/assemble/AssembleModelGeneratorTests.kt index 7a5f1a6167..7ca5a772ea 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/framework/assemble/AssembleModelGeneratorTests.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/framework/assemble/AssembleModelGeneratorTests.kt @@ -1,5 +1,11 @@ package org.utbot.framework.assemble +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test import org.utbot.examples.assemble.AssembleTestUtils import org.utbot.examples.assemble.ComplexField import org.utbot.examples.assemble.DirectAccess @@ -23,15 +29,16 @@ import org.utbot.examples.assemble.constructors.InheritComplexConstructor import org.utbot.examples.assemble.constructors.InheritPrimitiveConstructor import org.utbot.examples.assemble.constructors.PrimitiveConstructor import org.utbot.examples.assemble.constructors.PrimitiveConstructorWithDefaultField +import org.utbot.examples.assemble.constructors.PrivateConstructor import org.utbot.examples.assemble.constructors.PseudoComplexConstructor import org.utbot.examples.assemble.defaults.DefaultField import org.utbot.examples.assemble.defaults.DefaultFieldModifiedInConstructor import org.utbot.examples.assemble.defaults.DefaultFieldWithDirectAccessor -import org.utbot.examples.assemble.constructors.PrivateConstructor import org.utbot.examples.assemble.defaults.DefaultFieldWithSetter import org.utbot.examples.assemble.defaults.DefaultPackagePrivateField import org.utbot.examples.assemble.statics.StaticField import org.utbot.framework.plugin.api.ClassId +import org.utbot.framework.plugin.api.ExecutableId import org.utbot.framework.plugin.api.FieldId import org.utbot.framework.plugin.api.MethodId import org.utbot.framework.plugin.api.UtArrayModel @@ -42,22 +49,15 @@ import org.utbot.framework.plugin.api.UtNullModel import org.utbot.framework.plugin.api.UtPrimitiveModel import org.utbot.framework.plugin.api.util.UtContext import org.utbot.framework.plugin.api.util.UtContext.Companion.setUtContext +import org.utbot.framework.plugin.api.util.executableId import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.intArrayClassId import org.utbot.framework.plugin.api.util.intClassId +import org.utbot.framework.plugin.services.JdkInfoDefaultProvider +import org.utbot.framework.util.SootUtils import org.utbot.framework.util.instanceCounter import org.utbot.framework.util.modelIdCounter import kotlin.reflect.full.functions -import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertTrue -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Disabled -import org.junit.jupiter.api.Test -import org.utbot.framework.plugin.api.ExecutableId -import org.utbot.framework.plugin.api.util.executableId -import org.utbot.framework.util.SootUtils -import org.utbot.framework.util.sootMethod /** * Test classes must be located in the same folder as [AssembleTestUtils] class. @@ -72,7 +72,7 @@ class AssembleModelGeneratorTests { instanceCounter.set(0) modelIdCounter.set(0) statementsChain = mutableListOf() - SootUtils.runSoot(AssembleTestUtils::class.java, forceReload = false) + SootUtils.runSoot(AssembleTestUtils::class.java, forceReload = false, jdkInfo = JdkInfoDefaultProvider().info) context = setUtContext(UtContext(AssembleTestUtils::class.java.classLoader)) } diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/framework/modificators/UtBotFieldModificatorsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/framework/modificators/UtBotFieldModificatorsTest.kt index d8a85de389..a95244365a 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/framework/modificators/UtBotFieldModificatorsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/framework/modificators/UtBotFieldModificatorsTest.kt @@ -24,6 +24,7 @@ import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test +import org.utbot.framework.plugin.services.JdkInfoDefaultProvider import org.utbot.framework.util.SootUtils internal class UtBotFieldModificatorsTest { @@ -169,7 +170,11 @@ internal class UtBotFieldModificatorsTest { } private fun initAnalysis() { - SootUtils.runSoot(PrimitiveModifications::class.java, forceReload = false) + SootUtils.runSoot( + PrimitiveModifications::class.java, + forceReload = false, + jdkInfo = JdkInfoDefaultProvider().info + ) fieldsModificatorsSearcher = UtBotFieldsModificatorsSearcher() } 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 296e3eef45..544f44c958 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 @@ -29,6 +29,7 @@ import org.utbot.framework.plugin.api.util.primitiveByWrapper import org.utbot.framework.plugin.api.util.stringClassId import org.utbot.framework.plugin.api.util.withUtContext import org.utbot.framework.plugin.api.util.wrapperByPrimitive +import org.utbot.framework.plugin.services.JdkInfoDefaultProvider import org.utbot.fuzzer.FuzzedValue import org.utbot.fuzzer.ModelProvider import org.utbot.fuzzer.ModelProvider.Companion.yieldValue @@ -112,7 +113,7 @@ object UtBotJavaApi { testSets.addAll(withUtContext(utContext) { val buildPath = FileUtil.isolateClassFiles(classUnderTest).toPath() - TestCaseGenerator(buildPath, classpath, dependencyClassPath) + TestCaseGenerator(buildPath, classpath, dependencyClassPath, jdkInfo = JdkInfoDefaultProvider().info) .generate( methodsForAutomaticGeneration.map { it.methodToBeTestedFromUserInput.executableId @@ -172,7 +173,7 @@ object UtBotJavaApi { return withUtContext(UtContext(classUnderTest.classLoader)) { val buildPath = FileUtil.isolateClassFiles(classUnderTest).toPath() - TestCaseGenerator(buildPath, classpath, dependencyClassPath) + TestCaseGenerator(buildPath, classpath, dependencyClassPath, jdkInfo = JdkInfoDefaultProvider().info) .generate( methodsForAutomaticGeneration.map { it.methodToBeTestedFromUserInput.executableId diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/modifications/ConstructorAnalyzer.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/modifications/ConstructorAnalyzer.kt index 2960364095..6284c344ea 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/modifications/ConstructorAnalyzer.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/modifications/ConstructorAnalyzer.kt @@ -209,7 +209,7 @@ class ConstructorAnalyzer { private fun hasSuspiciousInstructions(jimpleBody: JimpleBody): Boolean = jimpleBody.units.any { it !is JIdentityStmt - && !(it is JAssignStmt && it.rightBox.value !is InvokeExpr) + && !(it is JAssignStmt && it.rightOp !is InvokeExpr) && it !is JInvokeStmt && it !is JReturnStmt && it !is JReturnVoidStmt 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 57c48a1016..8c8a35f602 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 @@ -34,6 +34,7 @@ import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.intArrayClassId import org.utbot.framework.plugin.api.util.utContext import org.utbot.framework.plugin.api.util.withUtContext +import org.utbot.framework.plugin.services.JdkInfo import org.utbot.framework.util.SootUtils import org.utbot.framework.util.jimpleBody import org.utbot.framework.util.toModel @@ -53,6 +54,7 @@ import kotlin.reflect.KCallable * Note: the instantiating of [TestCaseGenerator] may take some time, * because it requires initializing Soot for the current [buildDir] and [classpath]. * + * @param jdkInfo specifies the JRE and the runtime library version used for analysing system classes and user's code. * @param forceSootReload forces to reinitialize Soot even if the previous buildDir equals to [buildDir] and previous * classpath equals to [classpath]. This is the case for plugin scenario, as the source code may be modified. */ @@ -60,9 +62,10 @@ open class TestCaseGenerator( private val buildDir: Path, private val classpath: String?, private val dependencyPaths: String, + private val jdkInfo: JdkInfo, val engineActions: MutableList<(UtBotSymbolicEngine) -> Unit> = mutableListOf(), val isCanceled: () -> Boolean = { false }, - val forceSootReload: Boolean = true + val forceSootReload: Boolean = true, ) { private val logger: KLogger = KotlinLogging.logger {} private val timeoutLogger: KLogger = KotlinLogging.logger(logger.name + ".timeout") @@ -82,7 +85,7 @@ open class TestCaseGenerator( } timeoutLogger.trace().bracket("Soot initialization") { - SootUtils.runSoot(buildDir, classpath, forceSootReload) + SootUtils.runSoot(buildDir, classpath, forceSootReload, jdkInfo) } //warmup diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/util/SootUtils.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/util/SootUtils.kt index ebb5e8bc78..db738b1b7c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/util/SootUtils.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/util/SootUtils.kt @@ -40,6 +40,7 @@ import org.utbot.engine.overrides.strings.UtStringBuffer import org.utbot.engine.overrides.strings.UtStringBuilder import org.utbot.engine.pureJavaSignature import org.utbot.framework.plugin.api.ExecutableId +import org.utbot.framework.plugin.services.JdkInfo import soot.G import soot.PackManager import soot.Scene @@ -55,24 +56,28 @@ object SootUtils { /** * Runs Soot in tests if it hasn't already been done. * + * @param jdkInfo specifies the JRE and the runtime library version used for analysing system classes and user's + * code. * @param forceReload forces to reinitialize Soot even if the [previousBuildDir] equals to the class buildDir. */ - fun runSoot(clazz: java.lang.Class<*>, forceReload: kotlin.Boolean) { + fun runSoot(clazz: java.lang.Class<*>, forceReload: kotlin.Boolean, jdkInfo: JdkInfo) { val buildDir = FileUtil.locateClassPath(clazz) ?: FileUtil.isolateClassFiles(clazz) val buildDirPath = buildDir.toPath() - runSoot(buildDirPath, null, forceReload) + runSoot(buildDirPath, null, forceReload, jdkInfo) } /** + * @param jdkInfo specifies the JRE and the runtime library version used for analysing system classes and user's + * code. * @param forceReload forces to reinitialize Soot even if the [previousBuildDir] equals to [buildDirPath] and * [previousClassPath] equals to [classPath]. */ - fun runSoot(buildDirPath: Path, classPath: String?, forceReload: kotlin.Boolean) { + fun runSoot(buildDirPath: Path, classPath: String?, forceReload: kotlin.Boolean, jdkInfo: JdkInfo) { synchronized(this) { if (buildDirPath != previousBuildDir || classPath != previousClassPath || forceReload) { - initSoot(buildDirPath, classPath) + initSoot(buildDirPath, classPath, jdkInfo) previousBuildDir = buildDirPath previousClassPath = classPath } @@ -84,12 +89,14 @@ object SootUtils { } /** -Convert code to Jimple + * Convert code to Jimple */ -private fun initSoot(buildDir: Path, classpath: String?) { +private fun initSoot(buildDir: Path, classpath: String?, jdkInfo: JdkInfo) { G.reset() val options = Options.v() + G.v().initJdk(G.JreInfo(jdkInfo.path.toString(), jdkInfo.version)) // init Soot with the right jdk + options.apply { set_prepend_classpath(true) // set true to debug. Disabled because of a bug when two different variables diff --git a/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/TestSpecificTestCaseGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/TestSpecificTestCaseGenerator.kt index 6e2bacb77c..0b2c9d87dd 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/TestSpecificTestCaseGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/TestSpecificTestCaseGenerator.kt @@ -18,6 +18,7 @@ import org.utbot.framework.plugin.api.UtError import org.utbot.framework.plugin.api.UtExecution import org.utbot.framework.plugin.api.UtMethodTestSet import org.utbot.framework.plugin.api.util.id +import org.utbot.framework.plugin.services.JdkInfoDefaultProvider import org.utbot.framework.util.jimpleBody import java.nio.file.Path @@ -31,7 +32,15 @@ class TestSpecificTestCaseGenerator( dependencyPaths: String, engineActions: MutableList<(UtBotSymbolicEngine) -> Unit> = mutableListOf(), isCanceled: () -> Boolean = { false }, -): TestCaseGenerator(buildDir, classpath, dependencyPaths, engineActions, isCanceled, forceSootReload = false) { +): TestCaseGenerator( + buildDir, + classpath, + dependencyPaths, + JdkInfoDefaultProvider().info, + engineActions, + isCanceled, + forceSootReload = false +) { private val logger = KotlinLogging.logger {} diff --git a/utbot-gradle/src/main/kotlin/org/utbot/gradle/plugin/GenerateTestsAndSarifReportTask.kt b/utbot-gradle/src/main/kotlin/org/utbot/gradle/plugin/GenerateTestsAndSarifReportTask.kt index 4f7a74bb19..0352f8b890 100644 --- a/utbot-gradle/src/main/kotlin/org/utbot/gradle/plugin/GenerateTestsAndSarifReportTask.kt +++ b/utbot-gradle/src/main/kotlin/org/utbot/gradle/plugin/GenerateTestsAndSarifReportTask.kt @@ -14,6 +14,7 @@ import org.utbot.gradle.plugin.wrappers.GradleProjectWrapper import org.utbot.gradle.plugin.wrappers.SourceFindingStrategyGradle import org.utbot.gradle.plugin.wrappers.SourceSetWrapper import org.utbot.framework.plugin.sarif.TargetClassWrapper +import org.utbot.framework.plugin.services.JdkInfoDefaultProvider import java.io.File import java.net.URLClassLoader import javax.inject.Inject @@ -88,7 +89,12 @@ open class GenerateTestsAndSarifReportTask @Inject constructor( logger.debug().bracket("Generating tests for the '${sourceSet.sourceSet.name}' source set") { withUtContext(UtContext(sourceSet.classLoader)) { val testCaseGenerator = - TestCaseGenerator(sourceSet.workingDirectory, sourceSet.runtimeClasspath, dependencyPaths) + TestCaseGenerator( + sourceSet.workingDirectory, + sourceSet.runtimeClasspath, + dependencyPaths, + JdkInfoDefaultProvider().info + ) sourceSet.targetClasses.forEach { targetClass -> generateForClass(sourceSet, targetClass, testCaseGenerator) } 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 05d58a6cb8..7b8f308c3c 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 @@ -158,8 +158,8 @@ object UtTestsDialogProcessor { Paths.get(buildDir), classpath, pluginJarsPath.joinToString(separator = File.pathSeparator), - isCanceled = { indicator.isCanceled } - ) + JdkInfoService.provide(), + isCanceled = { indicator.isCanceled }) for (srcClass in model.srcClasses) { val methods = ReadAction.nonBlocking> { 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 50b11a2d06..2f5a27cfd2 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 @@ -1,30 +1,5 @@ package org.utbot.contest -import java.io.File -import java.lang.reflect.Method -import java.lang.reflect.Modifier -import java.net.URL -import java.net.URLClassLoader -import java.nio.file.Paths -import kotlin.concurrent.thread -import kotlin.math.max -import kotlin.math.min -import kotlin.reflect.KCallable -import kotlin.reflect.jvm.isAccessible -import kotlinx.coroutines.CancellationException -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.ObsoleteCoroutinesApi -import kotlinx.coroutines.SupervisorJob -import kotlinx.coroutines.currentCoroutineContext -import kotlinx.coroutines.delay -import kotlinx.coroutines.isActive -import kotlinx.coroutines.job -import kotlinx.coroutines.launch -import kotlinx.coroutines.newSingleThreadContext -import kotlinx.coroutines.runBlocking -import kotlinx.coroutines.withTimeoutOrNull -import kotlinx.coroutines.yield import mu.KotlinLogging import org.objectweb.asm.Type import org.utbot.common.FileUtil @@ -53,12 +28,38 @@ import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.jClass import org.utbot.framework.plugin.api.util.utContext import org.utbot.framework.plugin.api.util.withUtContext +import org.utbot.framework.plugin.services.JdkInfoService import org.utbot.framework.util.isKnownSyntheticMethod import org.utbot.fuzzer.UtFuzzedExecution import org.utbot.instrumentation.ConcreteExecutor import org.utbot.instrumentation.ConcreteExecutorPool import org.utbot.instrumentation.Settings import org.utbot.instrumentation.warmup.Warmup +import java.io.File +import java.lang.reflect.Method +import java.lang.reflect.Modifier +import java.net.URL +import java.net.URLClassLoader +import java.nio.file.Paths +import kotlin.concurrent.thread +import kotlin.math.max +import kotlin.math.min +import kotlin.reflect.KCallable +import kotlin.reflect.jvm.isAccessible +import kotlinx.coroutines.CancellationException +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.ObsoleteCoroutinesApi +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.currentCoroutineContext +import kotlinx.coroutines.delay +import kotlinx.coroutines.isActive +import kotlinx.coroutines.job +import kotlinx.coroutines.launch +import kotlinx.coroutines.newSingleThreadContext +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.withTimeoutOrNull +import kotlinx.coroutines.yield internal const val junitVersion = 4 private val logger = KotlinLogging.logger {} @@ -185,7 +186,7 @@ fun runGeneration( setOptions() //will not be executed in real contest logger.info().bracket("warmup: 1st optional soot initialization and executor warmup (not to be counted in time budget)") { - TestCaseGenerator(cut.classfileDir.toPath(), classpathString, dependencyPath) + TestCaseGenerator(cut.classfileDir.toPath(), classpathString, dependencyPath, JdkInfoService.provide()) } logger.info().bracket("warmup (first): kotlin reflection :: init") { prepareClass(ConcreteExecutorPool::class.java, "") @@ -226,7 +227,7 @@ fun runGeneration( val testCaseGenerator = logger.info().bracket("2nd optional soot initialization") { - TestCaseGenerator(cut.classfileDir.toPath(), classpathString, dependencyPath) + TestCaseGenerator(cut.classfileDir.toPath(), classpathString, dependencyPath, JdkInfoService.provide()) } diff --git a/utbot-maven/src/main/kotlin/org/utbot/maven/plugin/GenerateTestsAndSarifReportMojo.kt b/utbot-maven/src/main/kotlin/org/utbot/maven/plugin/GenerateTestsAndSarifReportMojo.kt index 3cbf92b228..130e75db6e 100644 --- a/utbot-maven/src/main/kotlin/org/utbot/maven/plugin/GenerateTestsAndSarifReportMojo.kt +++ b/utbot-maven/src/main/kotlin/org/utbot/maven/plugin/GenerateTestsAndSarifReportMojo.kt @@ -14,6 +14,7 @@ import org.utbot.framework.plugin.api.util.UtContext import org.utbot.framework.plugin.api.util.withUtContext import org.utbot.framework.plugin.sarif.GenerateTestsAndSarifReportFacade import org.utbot.framework.plugin.sarif.TargetClassWrapper +import org.utbot.framework.plugin.services.JdkInfoService import org.utbot.maven.plugin.extension.SarifMavenConfigurationProvider import org.utbot.maven.plugin.wrappers.MavenProjectWrapper import org.utbot.maven.plugin.wrappers.SourceFindingStrategyMaven @@ -175,7 +176,12 @@ class GenerateTestsAndSarifReportMojo : AbstractMojo() { logger.debug().bracket("Generating tests for the '${mavenProjectWrapper.mavenProject.name}' source set") { withUtContext(UtContext(mavenProjectWrapper.classLoader)) { val testCaseGenerator = - TestCaseGenerator(mavenProjectWrapper.workingDirectory, mavenProjectWrapper.runtimeClasspath, dependencyPaths) + TestCaseGenerator( + mavenProjectWrapper.workingDirectory, + mavenProjectWrapper.runtimeClasspath, + dependencyPaths, + JdkInfoService.provide() + ) mavenProjectWrapper.targetClasses.forEach { targetClass -> generateForClass(mavenProjectWrapper, targetClass, testCaseGenerator) } diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/ast/JimpleToASTMap.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/ast/JimpleToASTMap.kt index 13b0ed1673..2366df4915 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/ast/JimpleToASTMap.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/ast/JimpleToASTMap.kt @@ -167,7 +167,7 @@ class JimpleToASTMap(stmts: Iterable, methodDeclaration: MethodDeclaration val stmts = stmtToASTNode.keys.toTypedArray() for (index in stmts.indices) { val stmt = stmts[index] - if (stmt is JIdentityStmt && stmt.rightBox.value is JCaughtExceptionRef) { + if (stmt is JIdentityStmt && stmt.rightOp is JCaughtExceptionRef) { if (index + 1 < stmts.size) { val nextASTNode = stmtToASTNode[stmts[index + 1]] if (nextASTNode != null) { diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/SimpleCommentBuilder.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/SimpleCommentBuilder.kt index 3f8878f8e9..d085a5d3f0 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/SimpleCommentBuilder.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/SimpleCommentBuilder.kt @@ -260,7 +260,7 @@ open class SimpleCommentBuilder( if (recursion != null) { if (stmt is JAssignStmt) { - val name = (stmt.rightBox.value as JVirtualInvokeExpr).method.name + val name = (stmt.rightOp as JVirtualInvokeExpr).method.name val sentenceRecursionBlock = SimpleSentenceBlock(stringTemplates = stringTemplates) buildSentenceBlock(recursion, sentenceRecursionBlock, currentMethod) sentenceBlock.recursion = Pair(name, sentenceRecursionBlock) diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/SymbolicExecutionClusterCommentBuilder.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/SymbolicExecutionClusterCommentBuilder.kt index fa95017174..97663ff8b3 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/comment/SymbolicExecutionClusterCommentBuilder.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/comment/SymbolicExecutionClusterCommentBuilder.kt @@ -155,7 +155,7 @@ class SymbolicExecutionClusterCommentBuilder( if (recursion != null) { if (stmt is JAssignStmt) { - val name = (stmt.rightBox.value as JVirtualInvokeExpr).method.name + val name = (stmt.rightOp as JVirtualInvokeExpr).method.name val sentenceRecursionBlock = SimpleSentenceBlock(stringTemplates = StringsTemplatesPlural()) buildSentenceBlock(recursion, sentenceRecursionBlock, currentMethod) sentenceBlock.recursion = Pair(name, sentenceRecursionBlock) diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/name/SimpleNameBuilder.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/name/SimpleNameBuilder.kt index 5a9d7e17c5..2f0b2e6c99 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/name/SimpleNameBuilder.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/name/SimpleNameBuilder.kt @@ -434,7 +434,7 @@ class SimpleNameBuilder( if (recursion != null) { val name = when (stmt) { - is JAssignStmt -> "Recursion" + (stmt.rightBox.value as JVirtualInvokeExpr).method.name //todo through .convertNodeToString + is JAssignStmt -> "Recursion" + (stmt.rightOp as JVirtualInvokeExpr).method.name //todo through .convertNodeToString is JInvokeStmt -> "Recursion" + stmt.invokeExpr.method.name //todo through .convertNodeToString else -> "" } diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/tag/TagUtils.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/tag/TagUtils.kt index c4ce6c3ef2..59c748e1e6 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/tag/TagUtils.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/tag/TagUtils.kt @@ -60,7 +60,7 @@ fun getBasicTypeTag(stmt: Stmt): BasicTypeTag = when (stmt) { } fun basicIdentityTag(stmt: JIdentityStmt): BasicTypeTag { - if (stmt.rightBox.value is JCaughtExceptionRef) { + if (stmt.rightOp is JCaughtExceptionRef) { return BasicTypeTag.CaughtException } return BasicTypeTag.Initialization