Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing long summarization timeouts & mics #1151

Merged
merged 2 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ target/
.idea/
.gradle/
*.log
*.rdgen
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ object ClassUtil {
val clazz = classLoader.tryLoadClass(classFqn)
?: return null
val sourceFileName = withUtContext(UtContext(classLoader)) {
Instrumenter.computeSourceFileName(clazz) // finds the file name in bytecode
Instrumenter.adapter.computeSourceFileName(clazz) // finds the file name in bytecode
} ?: return null
val candidates = sourceCodeFiles.filter { sourceCodeFile ->
sourceCodeFile.endsWith(File(sourceFileName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import org.utbot.framework.plugin.api.util.id
import org.utbot.framework.plugin.api.util.jClass
import org.utbot.framework.plugin.services.JdkInfo
import org.utbot.framework.process.generated.*
import org.utbot.framework.util.Conflict
import org.utbot.framework.util.ConflictTriggers
import org.utbot.instrumentation.instrumentation.instrumenter.Instrumenter
import org.utbot.instrumentation.util.KryoHelper
import org.utbot.rd.CallsSynchronizer
import org.utbot.rd.ClientProtocolBuilder
Expand All @@ -33,13 +33,9 @@ import org.utbot.rd.loggers.UtRdKLoggerFactory
import org.utbot.sarif.RdSourceFindingStrategyFacade
import org.utbot.sarif.SarifReport
import org.utbot.summary.summarize
import soot.SootMethod
import soot.UnitPatchingChain
import soot.util.HashChain
import java.io.File
import java.net.URLClassLoader
import java.nio.file.Paths
import java.util.*
import kotlin.reflect.full.functions
import kotlin.time.Duration.Companion.seconds

Expand All @@ -56,6 +52,7 @@ suspend fun main(args: Array<String>) = runBlocking {
ClientProtocolBuilder().withProtocolTimeout(messageFromMainTimeoutMillis).start(port) {
settingsModel
rdSourceFindingStrategy
rdInstrumenterAdapter

AbstractSettings.setupFactory(RdSettingsContainerFactory(protocol))
val kryoHelper = KryoHelper(lifetime)
Expand All @@ -82,6 +79,7 @@ private fun EngineProcessModel.setup(
}
synchronizer.measureExecutionForTermination(createTestGenerator) { params ->
AnalyticsConfigureUtil.configureML()
Instrumenter.adapter = RdInstrumenter(realProtocol)
testGenerator = TestCaseGenerator(buildDirs = params.buildDir.map { Paths.get(it) },
classpath = params.classpath,
dependencyPaths = params.dependencyPaths,
Expand Down Expand Up @@ -150,7 +148,7 @@ private fun EngineProcessModel.setup(
codeGenerator.generateAsStringWithTestReport(testSets[testSetsId]!!)
.let {
testGenerationReports.add(it.testsGenerationReport)
RenderResult(it.generatedCode, kryoHelper.writeObject(it.utilClassKind))
RenderResult(it.generatedCode, it.utilClassKind?.javaClass?.simpleName)
}
}
synchronizer.measureExecutionForTermination(stopProcess) { synchronizer.stopProtocol() }
Expand All @@ -177,6 +175,7 @@ private fun EngineProcessModel.setup(
}
synchronizer.measureExecutionForTermination(writeSarifReport) { params ->
val reportFilePath = Paths.get(params.reportFilePath)
reportFilePath.parent.toFile().mkdirs()
reportFilePath.toFile().writeText(
SarifReport(
testSets[params.testSetsId]!!,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.utbot.framework.process

import com.jetbrains.rd.framework.IProtocol
import kotlinx.coroutines.runBlocking
import mu.KotlinLogging
import org.utbot.framework.process.generated.ComputeSourceFileByClassArguments
import org.utbot.framework.process.generated.rdInstrumenterAdapter
import org.utbot.instrumentation.instrumentation.instrumenter.InstrumenterAdapter
import java.io.File
import java.nio.file.Path

private val logger = KotlinLogging.logger { }

class RdInstrumenter(private val protocol: IProtocol): InstrumenterAdapter() {
override fun computeSourceFileByClass(
className: String,
packageName: String?,
directoryToSearchRecursively: Path
): File? = runBlocking {
logger.debug { "starting computeSourceFileByClass with classname - $className" }
val result = try {
protocol.rdInstrumenterAdapter.computeSourceFileByClass.startSuspending(
ComputeSourceFileByClassArguments(
className,
packageName
)
)
}
catch(e: Exception) {
logger.error(e) { "error during computeSourceFileByClass" }
throw e
}
logger.debug { "computeSourceFileByClass result for $className from idea: $result"}
return@runBlocking result?.let { File(it) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import kotlin.jvm.JvmStatic


/**
* #### Generated from [EngineProcessModel.kt:20]
* #### Generated from [EngineProcessModel.kt:30]
*/
class EngineProcessModel private constructor(
private val _setupUtContext: RdCall<SetupContextParams, Unit>,
Expand Down Expand Up @@ -73,7 +73,7 @@ class EngineProcessModel private constructor(
}


const val serializationHash = 4674749231408610997L
const val serializationHash = 3907671513584285891L

}
override val serializersOwner: ISerializersOwner get() = EngineProcessModel
Expand Down Expand Up @@ -180,7 +180,7 @@ val IProtocol.engineProcessModel get() = getOrCreateExtension(EngineProcessModel


/**
* #### Generated from [EngineProcessModel.kt:89]
* #### Generated from [EngineProcessModel.kt:99]
*/
data class FindMethodParamNamesArguments (
val classId: ByteArray,
Expand Down Expand Up @@ -243,7 +243,7 @@ data class FindMethodParamNamesArguments (


/**
* #### Generated from [EngineProcessModel.kt:93]
* #### Generated from [EngineProcessModel.kt:103]
*/
data class FindMethodParamNamesResult (
val paramNames: ByteArray
Expand Down Expand Up @@ -300,7 +300,7 @@ data class FindMethodParamNamesResult (


/**
* #### Generated from [EngineProcessModel.kt:82]
* #### Generated from [EngineProcessModel.kt:92]
*/
data class FindMethodsInClassMatchingSelectedArguments (
val classId: ByteArray,
Expand Down Expand Up @@ -363,7 +363,7 @@ data class FindMethodsInClassMatchingSelectedArguments (


/**
* #### Generated from [EngineProcessModel.kt:86]
* #### Generated from [EngineProcessModel.kt:96]
*/
data class FindMethodsInClassMatchingSelectedResult (
val executableIds: ByteArray
Expand Down Expand Up @@ -420,7 +420,7 @@ data class FindMethodsInClassMatchingSelectedResult (


/**
* #### Generated from [EngineProcessModel.kt:32]
* #### Generated from [EngineProcessModel.kt:42]
*/
data class GenerateParams (
val mockInstalled: Boolean,
Expand Down Expand Up @@ -543,7 +543,7 @@ data class GenerateParams (


/**
* #### Generated from [EngineProcessModel.kt:50]
* #### Generated from [EngineProcessModel.kt:60]
*/
data class GenerateResult (
val notEmptyCases: Int,
Expand Down Expand Up @@ -606,7 +606,7 @@ data class GenerateResult (


/**
* #### Generated from [EngineProcessModel.kt:101]
* #### Generated from [EngineProcessModel.kt:111]
*/
data class GenerateTestReportArgs (
val eventLogMessage: String?,
Expand Down Expand Up @@ -699,7 +699,7 @@ data class GenerateTestReportArgs (


/**
* #### Generated from [EngineProcessModel.kt:110]
* #### Generated from [EngineProcessModel.kt:120]
*/
data class GenerateTestReportResult (
val notifyMessage: String,
Expand Down Expand Up @@ -768,7 +768,7 @@ data class GenerateTestReportResult (


/**
* #### Generated from [EngineProcessModel.kt:21]
* #### Generated from [EngineProcessModel.kt:31]
*/
data class JdkInfo (
val path: String,
Expand Down Expand Up @@ -831,7 +831,7 @@ data class JdkInfo (


/**
* #### Generated from [EngineProcessModel.kt:54]
* #### Generated from [EngineProcessModel.kt:64]
*/
data class RenderParams (
val testSetsId: Long,
Expand Down Expand Up @@ -972,11 +972,11 @@ data class RenderParams (


/**
* #### Generated from [EngineProcessModel.kt:71]
* #### Generated from [EngineProcessModel.kt:81]
*/
data class RenderResult (
val generatedCode: String,
val utilClassKind: ByteArray
val utilClassKind: String?
) : IPrintable {
//companion

Expand All @@ -986,13 +986,13 @@ data class RenderResult (
@Suppress("UNCHECKED_CAST")
override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): RenderResult {
val generatedCode = buffer.readString()
val utilClassKind = buffer.readByteArray()
val utilClassKind = buffer.readNullable { buffer.readString() }
return RenderResult(generatedCode, utilClassKind)
}

override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: RenderResult) {
buffer.writeString(value.generatedCode)
buffer.writeByteArray(value.utilClassKind)
buffer.writeNullable(value.utilClassKind) { buffer.writeString(it) }
}


Expand All @@ -1009,15 +1009,15 @@ data class RenderResult (
other as RenderResult

if (generatedCode != other.generatedCode) return false
if (!(utilClassKind contentEquals other.utilClassKind)) return false
if (utilClassKind != other.utilClassKind) return false

return true
}
//hash code trait
override fun hashCode(): Int {
var __r = 0
__r = __r*31 + generatedCode.hashCode()
__r = __r*31 + utilClassKind.contentHashCode()
__r = __r*31 + if (utilClassKind != null) utilClassKind.hashCode() else 0
return __r
}
//pretty print
Expand All @@ -1035,7 +1035,7 @@ data class RenderResult (


/**
* #### Generated from [EngineProcessModel.kt:75]
* #### Generated from [EngineProcessModel.kt:85]
*/
data class SetupContextParams (
val classpathForUrlsClassloader: List<String>
Expand Down Expand Up @@ -1092,7 +1092,7 @@ data class SetupContextParams (


/**
* #### Generated from [EngineProcessModel.kt:78]
* #### Generated from [EngineProcessModel.kt:88]
*/
data class Signature (
val name: String,
Expand Down Expand Up @@ -1155,7 +1155,7 @@ data class Signature (


/**
* #### Generated from [EngineProcessModel.kt:26]
* #### Generated from [EngineProcessModel.kt:36]
*/
data class TestGeneratorParams (
val buildDir: Array<String>,
Expand Down Expand Up @@ -1230,7 +1230,7 @@ data class TestGeneratorParams (


/**
* #### Generated from [EngineProcessModel.kt:96]
* #### Generated from [EngineProcessModel.kt:106]
*/
data class WriteSarifReportArguments (
val testSetsId: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class EngineProcessProtocolRoot private constructor(
override fun registerSerializersCore(serializers: ISerializers) {
EngineProcessProtocolRoot.register(serializers)
EngineProcessModel.register(serializers)
RdInstrumenterAdapter.register(serializers)
RdSourceFindingStrategy.register(serializers)
}

Expand Down
Loading