Abstract FIR modularized tests
This commit is contained in:
committed by
Mikhail Glukhikh
parent
60a73ca13f
commit
36ab325394
+95
@@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.fir
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
||||||
|
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
|
||||||
|
import org.w3c.dom.Node
|
||||||
|
import org.w3c.dom.NodeList
|
||||||
|
import java.io.File
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory
|
||||||
|
|
||||||
|
data class ModuleData(
|
||||||
|
val name: String,
|
||||||
|
val qualifiedName: String,
|
||||||
|
val classpath: List<File>,
|
||||||
|
val sources: List<File>,
|
||||||
|
val javaSourceRoots: List<File>
|
||||||
|
)
|
||||||
|
|
||||||
|
private fun NodeList.toList(): List<Node> {
|
||||||
|
val list = mutableListOf<Node>()
|
||||||
|
for (index in 0 until this.length) {
|
||||||
|
list += item(index)
|
||||||
|
}
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private val Node.childNodesList get() = childNodes.toList()
|
||||||
|
|
||||||
|
abstract class AbstractModularizedTest : KtUsefulTestCase() {
|
||||||
|
private fun loadModule(file: File): ModuleData {
|
||||||
|
|
||||||
|
val factory = DocumentBuilderFactory.newInstance()
|
||||||
|
factory.isIgnoringComments = true
|
||||||
|
factory.isIgnoringElementContentWhitespace = true
|
||||||
|
val builder = factory.newDocumentBuilder()
|
||||||
|
val document = builder.parse(file)
|
||||||
|
val moduleElement = document.childNodes.item(0).childNodesList.first { it.nodeType == Node.ELEMENT_NODE }
|
||||||
|
val moduleName = moduleElement.attributes.getNamedItem("name").nodeValue
|
||||||
|
val outputDir = moduleElement.attributes.getNamedItem("outputDir").nodeValue
|
||||||
|
val qualifiedModuleName = outputDir.substringAfterLast("/")
|
||||||
|
val javaSourceRoots = mutableListOf<File>()
|
||||||
|
val classpath = mutableListOf<File>()
|
||||||
|
val sources = mutableListOf<File>()
|
||||||
|
|
||||||
|
for (index in 0 until moduleElement.childNodes.length) {
|
||||||
|
val item = moduleElement.childNodes.item(index)
|
||||||
|
|
||||||
|
if (item.nodeName == "classpath") {
|
||||||
|
val path = item.attributes.getNamedItem("path").nodeValue
|
||||||
|
if (path != outputDir) {
|
||||||
|
classpath += File(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (item.nodeName == "javaSourceRoots") {
|
||||||
|
javaSourceRoots += File(item.attributes.getNamedItem("path").nodeValue)
|
||||||
|
}
|
||||||
|
if (item.nodeName == "sources") {
|
||||||
|
sources += File(item.attributes.getNamedItem("path").nodeValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ModuleData(moduleName, qualifiedModuleName, classpath, sources, javaSourceRoots)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected abstract fun beforePass()
|
||||||
|
protected abstract fun afterPass()
|
||||||
|
protected abstract fun processModule(moduleData: ModuleData): ProcessorAction
|
||||||
|
|
||||||
|
protected fun runTestOnce(pass: Int) {
|
||||||
|
beforePass()
|
||||||
|
val testDataPath = "/Users/jetbrains/jps"
|
||||||
|
val root = File(testDataPath)
|
||||||
|
|
||||||
|
println("BASE PATH: ${root.absolutePath}")
|
||||||
|
|
||||||
|
val modules =
|
||||||
|
root.listFiles().sortedBy { it.lastModified() }.map { loadModule(it) }
|
||||||
|
.filter { it.qualifiedName == "kotlin.idea.main" }
|
||||||
|
|
||||||
|
|
||||||
|
for (module in modules.progress(step = 0.0) { "Analyzing ${it.qualifiedName}" }) {
|
||||||
|
if (processModule(module).stop()) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
afterPass()
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
-78
@@ -21,30 +21,17 @@ import org.jetbrains.kotlin.fir.dump.MultiModuleHtmlFirDump
|
|||||||
import org.jetbrains.kotlin.fir.resolve.FirProvider
|
import org.jetbrains.kotlin.fir.resolve.FirProvider
|
||||||
import org.jetbrains.kotlin.fir.resolve.impl.FirProviderImpl
|
import org.jetbrains.kotlin.fir.resolve.impl.FirProviderImpl
|
||||||
import org.jetbrains.kotlin.fir.resolve.transformers.FirTotalResolveTransformer
|
import org.jetbrains.kotlin.fir.resolve.transformers.FirTotalResolveTransformer
|
||||||
|
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
||||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
import org.jetbrains.kotlin.test.TestJdkKind
|
import org.jetbrains.kotlin.test.TestJdkKind
|
||||||
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
|
|
||||||
import org.w3c.dom.Node
|
|
||||||
import org.w3c.dom.NodeList
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.PrintStream
|
import java.io.PrintStream
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.xml.parsers.DocumentBuilderFactory
|
|
||||||
import kotlin.system.measureNanoTime
|
import kotlin.system.measureNanoTime
|
||||||
|
|
||||||
|
|
||||||
private fun NodeList.toList(): List<Node> {
|
|
||||||
val list = mutableListOf<Node>()
|
|
||||||
for (index in 0 until this.length) {
|
|
||||||
list += item(index)
|
|
||||||
}
|
|
||||||
return list
|
|
||||||
}
|
|
||||||
|
|
||||||
private val Node.childNodesList get() = childNodes.toList()
|
|
||||||
|
|
||||||
private const val FAIL_FAST = true
|
private const val FAIL_FAST = true
|
||||||
private const val DUMP_FIR = true
|
private const val DUMP_FIR = true
|
||||||
|
|
||||||
@@ -52,18 +39,9 @@ private const val FIR_DUMP_PATH = "tmp/firDump"
|
|||||||
private const val FIR_HTML_DUMP_PATH = "tmp/firDump-html"
|
private const val FIR_HTML_DUMP_PATH = "tmp/firDump-html"
|
||||||
private const val FIR_LOGS_PATH = "tmp/fir-logs"
|
private const val FIR_LOGS_PATH = "tmp/fir-logs"
|
||||||
|
|
||||||
private data class ModuleData(
|
|
||||||
val name: String,
|
|
||||||
val qualifiedName: String,
|
|
||||||
val classpath: List<File>,
|
|
||||||
val sources: List<File>,
|
|
||||||
val javaSourceRoots: List<File>
|
|
||||||
)
|
|
||||||
|
|
||||||
private const val PASSES = 1
|
private const val PASSES = 1
|
||||||
|
|
||||||
class FirResolveModularizedTotalKotlinTest : KtUsefulTestCase() {
|
class FirResolveModularizedTotalKotlinTest : AbstractModularizedTest() {
|
||||||
|
|
||||||
|
|
||||||
private lateinit var bench: FirResolveBench
|
private lateinit var bench: FirResolveBench
|
||||||
private lateinit var dump: MultiModuleHtmlFirDump
|
private lateinit var dump: MultiModuleHtmlFirDump
|
||||||
@@ -115,7 +93,7 @@ class FirResolveModularizedTotalKotlinTest : KtUsefulTestCase() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun processModule(moduleData: ModuleData) {
|
override fun processModule(moduleData: ModuleData): ProcessorAction {
|
||||||
val configurationKind = ConfigurationKind.ALL
|
val configurationKind = ConfigurationKind.ALL
|
||||||
val testJdkKind = TestJdkKind.FULL_JDK
|
val testJdkKind = TestJdkKind.FULL_JDK
|
||||||
|
|
||||||
@@ -138,63 +116,15 @@ class FirResolveModularizedTotalKotlinTest : KtUsefulTestCase() {
|
|||||||
runAnalysis(moduleData, environment)
|
runAnalysis(moduleData, environment)
|
||||||
|
|
||||||
Disposer.dispose(disposable)
|
Disposer.dispose(disposable)
|
||||||
|
if (bench.hasFiles && FAIL_FAST) return ProcessorAction.STOP
|
||||||
|
return ProcessorAction.NEXT
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadModule(file: File): ModuleData {
|
override fun beforePass() {
|
||||||
|
|
||||||
val factory = DocumentBuilderFactory.newInstance()
|
|
||||||
factory.isIgnoringComments = true
|
|
||||||
factory.isIgnoringElementContentWhitespace = true
|
|
||||||
val builder = factory.newDocumentBuilder()
|
|
||||||
val document = builder.parse(file)
|
|
||||||
val moduleElement = document.childNodes.item(0).childNodesList.first { it.nodeType == Node.ELEMENT_NODE }
|
|
||||||
val moduleName = moduleElement.attributes.getNamedItem("name").nodeValue
|
|
||||||
val outputDir = moduleElement.attributes.getNamedItem("outputDir").nodeValue
|
|
||||||
val qualifiedModuleName = outputDir.substringAfterLast("/")
|
|
||||||
val javaSourceRoots = mutableListOf<File>()
|
|
||||||
val classpath = mutableListOf<File>()
|
|
||||||
val sources = mutableListOf<File>()
|
|
||||||
|
|
||||||
for (index in 0 until moduleElement.childNodes.length) {
|
|
||||||
val item = moduleElement.childNodes.item(index)
|
|
||||||
|
|
||||||
if (item.nodeName == "classpath") {
|
|
||||||
val path = item.attributes.getNamedItem("path").nodeValue
|
|
||||||
if (path != outputDir) {
|
|
||||||
classpath += File(path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (item.nodeName == "javaSourceRoots") {
|
|
||||||
javaSourceRoots += File(item.attributes.getNamedItem("path").nodeValue)
|
|
||||||
}
|
|
||||||
if (item.nodeName == "sources") {
|
|
||||||
sources += File(item.attributes.getNamedItem("path").nodeValue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ModuleData(moduleName, qualifiedModuleName, classpath, sources, javaSourceRoots)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private fun runTestOnce(pass: Int) {
|
|
||||||
if (DUMP_FIR) dump = MultiModuleHtmlFirDump(File(FIR_HTML_DUMP_PATH))
|
if (DUMP_FIR) dump = MultiModuleHtmlFirDump(File(FIR_HTML_DUMP_PATH))
|
||||||
val testDataPath = "/Users/jetbrains/jps"
|
}
|
||||||
val root = File(testDataPath)
|
|
||||||
|
|
||||||
println("BASE PATH: ${root.absolutePath}")
|
|
||||||
|
|
||||||
val modules =
|
|
||||||
root.listFiles().sortedBy { it.lastModified() }.map { loadModule(it) }
|
|
||||||
// .sortedByDescending { it.name == "idea" }
|
|
||||||
|
|
||||||
|
|
||||||
for (module in modules.progress(step = 0.0) { "Analyzing ${it.qualifiedName}" }) {
|
|
||||||
processModule(module)
|
|
||||||
if (bench.hasFiles && FAIL_FAST) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
override fun afterPass() {
|
||||||
bench.report(System.out, errorTypeReports = false)
|
bench.report(System.out, errorTypeReports = false)
|
||||||
|
|
||||||
saveReport()
|
saveReport()
|
||||||
|
|||||||
+9
-79
@@ -15,37 +15,21 @@ import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
|||||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler
|
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler
|
||||||
|
import org.jetbrains.kotlin.config.*
|
||||||
|
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
||||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
import org.jetbrains.kotlin.test.TestJdkKind
|
import org.jetbrains.kotlin.test.TestJdkKind
|
||||||
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
|
|
||||||
import org.w3c.dom.Node
|
|
||||||
import org.w3c.dom.NodeList
|
|
||||||
import java.io.File
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory
|
|
||||||
import kotlin.system.measureNanoTime
|
import kotlin.system.measureNanoTime
|
||||||
|
|
||||||
|
|
||||||
private fun NodeList.toList(): List<Node> {
|
class NonFirResolveModularizedTotalKotlinTest : AbstractModularizedTest() {
|
||||||
val list = mutableListOf<Node>()
|
|
||||||
for (index in 0 until this.length) {
|
|
||||||
list += item(index)
|
|
||||||
}
|
|
||||||
return list
|
|
||||||
}
|
|
||||||
|
|
||||||
private val Node.childNodesList get() = childNodes.toList()
|
|
||||||
|
|
||||||
|
|
||||||
private data class XModuleData(val name: String, val classpath: List<File>, val sources: List<File>, val javaSourceRoots: List<File>)
|
|
||||||
|
|
||||||
class NonFirResolveModularizedTotalKotlinTest : KtUsefulTestCase() {
|
|
||||||
|
|
||||||
|
|
||||||
private var totalTime = 0L
|
private var totalTime = 0L
|
||||||
private var files = 0
|
private var files = 0
|
||||||
|
|
||||||
private fun runAnalysis(moduleData: XModuleData, environment: KotlinCoreEnvironment) {
|
private fun runAnalysis(moduleData: ModuleData, environment: KotlinCoreEnvironment) {
|
||||||
val project = environment.project
|
val project = environment.project
|
||||||
|
|
||||||
val time = measureNanoTime {
|
val time = measureNanoTime {
|
||||||
@@ -58,7 +42,7 @@ class NonFirResolveModularizedTotalKotlinTest : KtUsefulTestCase() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun processModule(moduleData: XModuleData) {
|
override fun processModule(moduleData: ModuleData): ProcessorAction {
|
||||||
val configurationKind = ConfigurationKind.ALL
|
val configurationKind = ConfigurationKind.ALL
|
||||||
val testJdkKind = TestJdkKind.FULL_JDK
|
val testJdkKind = TestJdkKind.FULL_JDK
|
||||||
|
|
||||||
@@ -92,73 +76,19 @@ class NonFirResolveModularizedTotalKotlinTest : KtUsefulTestCase() {
|
|||||||
})
|
})
|
||||||
val environment = KotlinCoreEnvironment.createForTests(disposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
val environment = KotlinCoreEnvironment.createForTests(disposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
||||||
|
|
||||||
// Extensions.getArea(environment.project)
|
|
||||||
// .getExtensionPoint(PsiElementFinder.EP_NAME)
|
|
||||||
// .unregisterExtension(JavaElementFinder::class.java)
|
|
||||||
|
|
||||||
println("Processing module: ${moduleData.name}")
|
|
||||||
runAnalysis(moduleData, environment)
|
runAnalysis(moduleData, environment)
|
||||||
|
|
||||||
Disposer.dispose(disposable)
|
Disposer.dispose(disposable)
|
||||||
}
|
return ProcessorAction.NEXT
|
||||||
|
|
||||||
private fun loadModule(file: File): XModuleData {
|
|
||||||
|
|
||||||
val factory = DocumentBuilderFactory.newInstance()
|
|
||||||
factory.isIgnoringComments = true
|
|
||||||
factory.isIgnoringElementContentWhitespace = true
|
|
||||||
val builder = factory.newDocumentBuilder()
|
|
||||||
val document = builder.parse(file)
|
|
||||||
val moduleElement = document.childNodes.item(0).childNodesList.first { it.nodeType == Node.ELEMENT_NODE }
|
|
||||||
val moduleName = moduleElement.attributes.getNamedItem("name").nodeValue
|
|
||||||
val javaSourceRoots = mutableListOf<File>()
|
|
||||||
val classpath = mutableListOf<File>()
|
|
||||||
val sources = mutableListOf<File>()
|
|
||||||
|
|
||||||
for (index in 0 until moduleElement.childNodes.length) {
|
|
||||||
val item = moduleElement.childNodes.item(index)
|
|
||||||
|
|
||||||
if (item.nodeName == "classpath") {
|
|
||||||
classpath += File(item.attributes.getNamedItem("path").nodeValue)
|
|
||||||
}
|
|
||||||
if (item.nodeName == "javaSourceRoots") {
|
|
||||||
javaSourceRoots += File(item.attributes.getNamedItem("path").nodeValue)
|
|
||||||
}
|
|
||||||
if (item.nodeName == "sources") {
|
|
||||||
sources += File(item.attributes.getNamedItem("path").nodeValue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return XModuleData(moduleName, classpath, sources, javaSourceRoots)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun runTestLocal() {
|
override fun afterPass() {}
|
||||||
val testDataPath = "/Users/jetbrains/jps"
|
override fun beforePass() {}
|
||||||
val root = File(testDataPath)
|
|
||||||
|
|
||||||
println("BASE PATH: ${root.absolutePath}")
|
|
||||||
|
|
||||||
val modules =
|
|
||||||
root.listFiles().sortedBy { it.lastModified() }.map { loadModule(it) }
|
|
||||||
|
|
||||||
// .sortedBy { !it.sources.any { it.nameWithoutExtension == "KotlinSearchEverywhereClassifier" } }
|
|
||||||
|
|
||||||
|
|
||||||
for (module in modules.progress { "Analyzing ${it.name}" }) {
|
|
||||||
processModule(module)
|
|
||||||
}
|
|
||||||
|
|
||||||
println("Total time: ${totalTime * 1e-6} ms, ${(totalTime * 1e-6) / files} ms per file")
|
|
||||||
totalTime = 0
|
|
||||||
files = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
fun testTotalKotlin() {
|
fun testTotalKotlin() {
|
||||||
//Thread.sleep(5000)
|
|
||||||
for (i in 0..2) {
|
for (i in 0..2) {
|
||||||
println("Pass $i")
|
runTestOnce(i)
|
||||||
runTestLocal()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user