Simple test with daemon compilation, minor fixes mostly for easier testing
This commit is contained in:
@@ -157,19 +157,33 @@ public class KotlinCompilerClient {
|
|||||||
return connectToService(compilerId, daemonOptions, errStream)
|
return connectToService(compilerId, daemonOptions, errStream)
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun shutdownCompileService(): Unit {
|
public fun shutdownCompileService(daemonOptions: DaemonOptions): Unit {
|
||||||
KotlinCompilerClient.connectToCompileService(CompilerId(), DaemonLaunchingOptions(), DaemonOptions(), System.out, autostart = false, checkId = false)
|
KotlinCompilerClient.connectToCompileService(CompilerId(), DaemonLaunchingOptions(), daemonOptions, System.out, autostart = false, checkId = false)
|
||||||
?.shutdown()
|
?.shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun incrementalCompile(compiler: CompileService, args: Array<String>, caches: Map<String, IncrementalCache>, out: OutputStream): Int {
|
public fun shutdownCompileService(): Unit {
|
||||||
|
shutdownCompileService(DaemonOptions())
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun compile(compiler: CompileService, args: Array<out String>, out: OutputStream): Int {
|
||||||
|
|
||||||
|
val outStrm = RemoteOutputStreamServer(out)
|
||||||
|
try {
|
||||||
|
return compiler.remoteCompile(args, outStrm, CompileService.OutputFormat.PLAIN)
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
outStrm.disconnect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun incrementalCompile(compiler: CompileService, args: Array<out String>, caches: Map<String, IncrementalCache>, out: OutputStream): Int {
|
||||||
|
|
||||||
val outStrm = RemoteOutputStreamServer(out)
|
val outStrm = RemoteOutputStreamServer(out)
|
||||||
val cacheServers = hashMapOf<String, RemoteIncrementalCacheServer>()
|
val cacheServers = hashMapOf<String, RemoteIncrementalCacheServer>()
|
||||||
try {
|
try {
|
||||||
caches.forEach { cacheServers.put( it.getKey(), RemoteIncrementalCacheServer( it.getValue())) }
|
caches.forEach { cacheServers.put( it.getKey(), RemoteIncrementalCacheServer( it.getValue())) }
|
||||||
val res = compiler.remoteIncrementalCompile(args, cacheServers, outStrm, CompileService.OutputFormat.XML)
|
return compiler.remoteIncrementalCompile(args, cacheServers, outStrm, CompileService.OutputFormat.XML)
|
||||||
return res
|
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
cacheServers.forEach { it.getValue().disconnect() }
|
cacheServers.forEach { it.getValue().disconnect() }
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public interface CompileService : Remote {
|
|||||||
|
|
||||||
throws(RemoteException::class)
|
throws(RemoteException::class)
|
||||||
public fun remoteIncrementalCompile(
|
public fun remoteIncrementalCompile(
|
||||||
args: Array<String>,
|
args: Array<out String>,
|
||||||
caches: Map<String, RemoteIncrementalCache>,
|
caches: Map<String, RemoteIncrementalCache>,
|
||||||
outputStream: RemoteOutputStream,
|
outputStream: RemoteOutputStream,
|
||||||
outputFormat: OutputFormat): Int
|
outputFormat: OutputFormat): Int
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ class CompileServiceImpl<Compiler: CLICompiler<*>>(
|
|||||||
val res = body()
|
val res = body()
|
||||||
val endTime = System.nanoTime()
|
val endTime = System.nanoTime()
|
||||||
val endMem = usedMemory() / 1024
|
val endMem = usedMemory() / 1024
|
||||||
log.info("Done")
|
log.info("Done with result " + res.toString())
|
||||||
log.info("Elapsed time: " + TimeUnit.NANOSECONDS.toMillis(endTime - startTime) + " ms")
|
log.info("Elapsed time: " + TimeUnit.NANOSECONDS.toMillis(endTime - startTime) + " ms")
|
||||||
log.info("Used memory: $endMem kb (${"%+d".format(endMem - startMem)} kb)")
|
log.info("Used memory: $endMem kb (${"%+d".format(endMem - startMem)} kb)")
|
||||||
return res
|
return res
|
||||||
@@ -178,7 +178,7 @@ class CompileServiceImpl<Compiler: CLICompiler<*>>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun remoteIncrementalCompile(args: Array<String>, caches: Map<String, CompileService.RemoteIncrementalCache>, errStream: RemoteOutputStream, outputFormat: CompileService.OutputFormat): Int =
|
override fun remoteIncrementalCompile(args: Array<out String>, caches: Map<String, CompileService.RemoteIncrementalCache>, errStream: RemoteOutputStream, outputFormat: CompileService.OutputFormat): Int =
|
||||||
ifAlive {
|
ifAlive {
|
||||||
checkedCompile(args) {
|
checkedCompile(args) {
|
||||||
val strm = RemoteOutputStreamClient(errStream)
|
val strm = RemoteOutputStreamClient(errStream)
|
||||||
|
|||||||
@@ -26,5 +26,7 @@
|
|||||||
<orderEntry type="module" module-name="js.serializer" />
|
<orderEntry type="module" module-name="js.serializer" />
|
||||||
<orderEntry type="module" module-name="js.translator" scope="TEST" />
|
<orderEntry type="module" module-name="js.translator" scope="TEST" />
|
||||||
<orderEntry type="module" module-name="util" />
|
<orderEntry type="module" module-name="util" />
|
||||||
|
<orderEntry type="module" module-name="kotlinr" />
|
||||||
|
<orderEntry type="module" module-name="rmi-interface" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.daemon
|
||||||
|
|
||||||
|
import junit.framework.TestCase
|
||||||
|
import org.jetbrains.kotlin.cli.CliBaseTest
|
||||||
|
import org.jetbrains.kotlin.integration.KotlinIntegrationTestBase
|
||||||
|
import org.jetbrains.kotlin.rmi.CompilerId
|
||||||
|
import org.jetbrains.kotlin.rmi.DaemonLaunchingOptions
|
||||||
|
import org.jetbrains.kotlin.rmi.DaemonOptions
|
||||||
|
import org.jetbrains.kotlin.rmi.kotlinr.KotlinCompilerClient
|
||||||
|
import org.jetbrains.kotlin.test.JetTestUtils
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
val KOTLIN_DAEMON_TEST_PORT = 19753
|
||||||
|
|
||||||
|
public class CompilerDaemonTest : KotlinIntegrationTestBase() {
|
||||||
|
|
||||||
|
data class CompilerResults(val resultCode: Int, val out: String)
|
||||||
|
|
||||||
|
val daemonOptions = DaemonOptions(port = KOTLIN_DAEMON_TEST_PORT)
|
||||||
|
val daemonLaunchingOptions = DaemonLaunchingOptions()
|
||||||
|
val compilerId by lazy { CompilerId.makeCompilerId( File(KotlinIntegrationTestBase.getCompilerLib(), "kotlin-compiler.jar"),
|
||||||
|
File("dependencies/bootstrap-compiler/Kotlin/kotlinc/lib/kotlin-runtime.jar"),
|
||||||
|
File("dependencies/bootstrap-compiler/Kotlin/kotlinc/lib/kotlin-reflect.jar")) }
|
||||||
|
|
||||||
|
private fun compileOnDaemon(args: Array<out String>): CompilerResults {
|
||||||
|
val daemon = KotlinCompilerClient.connectToCompileService(compilerId, daemonLaunchingOptions, daemonOptions, System.err, autostart = true, checkId = true)
|
||||||
|
TestCase.assertNotNull("failed to connect daemon", daemon)
|
||||||
|
val strm = ByteArrayOutputStream()
|
||||||
|
val code = KotlinCompilerClient.compile(daemon!!, args, strm)
|
||||||
|
return CompilerResults(code, strm.toString())
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun runDaemonCompilerTwice(logName: String, vararg arguments: String): Unit {
|
||||||
|
KotlinCompilerClient.shutdownCompileService(daemonOptions)
|
||||||
|
|
||||||
|
try {
|
||||||
|
val res1 = compileOnDaemon(arguments)
|
||||||
|
TestCase.assertEquals("first compilation failed:\n${res1.out}", 0, res1.resultCode)
|
||||||
|
val res2 = compileOnDaemon(arguments)
|
||||||
|
TestCase.assertEquals("second compilation failed:\n${res2.out}", 0, res2.resultCode)
|
||||||
|
TestCase.assertEquals("build results differ", CliBaseTest.removePerfOutput(res1.out), CliBaseTest.removePerfOutput(res2.out))
|
||||||
|
// TODO: add performance comparison assert
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
KotlinCompilerClient.shutdownCompileService(daemonOptions)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getTestBaseDir(): String = JetTestUtils.getTestDataPathBase() + "/integration/smoke/" + getTestName(true)
|
||||||
|
|
||||||
|
private fun run(logName: String, vararg args: String): Int = runJava(getTestBaseDir(), logName, *args)
|
||||||
|
|
||||||
|
public fun testHelloApp() {
|
||||||
|
val jar = tmpdir.absolutePath + File.separator + "hello.jar"
|
||||||
|
|
||||||
|
runDaemonCompilerTwice("hello.compile", "-include-runtime", File(getTestBaseDir(), "hello.kt").absolutePath, "-d", jar)
|
||||||
|
run("hello.run", "-cp", jar, "Hello.HelloPackage")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -133,7 +133,7 @@ public abstract class KotlinIntegrationTestBase extends TestCaseWithTmpdir {
|
|||||||
return runtime;
|
return runtime;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static File getCompilerLib() {
|
public static File getCompilerLib() {
|
||||||
File file = PathUtil.getKotlinPathsForDistDirectory().getLibPath().getAbsoluteFile();
|
File file = PathUtil.getKotlinPathsForDistDirectory().getLibPath().getAbsoluteFile();
|
||||||
assertTrue("Lib directory doesn't exist. Run 'ant dist'", file.isDirectory());
|
assertTrue("Lib directory doesn't exist. Run 'ant dist'", file.isDirectory());
|
||||||
return file;
|
return file;
|
||||||
|
|||||||
Reference in New Issue
Block a user