Remote test execution for cross compiled tests. Run it like:

$ ./gradlew backend.native:tests:run \
    -Premote=user@111.22.33.444 -Ptest_target=raspberrypi

The new gradle command line options:

    -Pbuild_flags  renamed -Pkonanc_flags.
    -Ptest_flags   provides compiler flags to the test builds.
    -Ptest_target  properly sets up compiler as well as interop
                   to cross compile tests.
    -Premote       specifies remote host and login.
This commit is contained in:
Alexander Gorshenev
2017-03-22 17:57:40 +03:00
committed by alexander-gorshenev
parent 826b3fc3f2
commit 334d2f0ee6
11 changed files with 171 additions and 37 deletions
@@ -0,0 +1,69 @@
package org.jetbrains.kotlin
import org.gradle.api.Action
import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.process.ExecResult
import org.gradle.process.ExecSpec
import org.gradle.util.ConfigureUtil
// This class provides process.execRemote -- a drop-in replacement for process.exec .
// If we provide -Premote=user@host the binaries are executed on a remote host
// If we omit -Premote then the binary is executed locally as usual.
class ExecRemote {
private final Project project
private final String remote = null
private final String remoteDir = null
ExecRemote(Project project) {
this.project = project
if (project.hasProperty('remote')) {
remote = project.ext.remote
remoteDir = uniqSessionName()
createRemoteDir()
}
}
private String uniqSessionName() {
def date = new Date().format('yyyyMMddHHmmss')
return project.ext.remoteRoot + File.createTempFile(System.properties['user.name'], "_" + date)
}
private createRemoteDir() {
project.exec {
commandLine('ssh', remote, 'mkdir', '-p', remoteDir)
}
}
private upload(String fileName) {
project.exec {
commandLine('scp', fileName, "${remote}:${remoteDir}")
}
}
public ExecResult execRemote(Action<? super ExecSpec> action) {
Action<? super ExecSpec> extendedAction = new Action<ExecSpec>() {
@Override
void execute(ExecSpec execSpec) {
action.execute(execSpec)
if (remote == null) return
execSpec.with {
upload(getExecutable())
executable = "$remoteDir/${new File(executable).name}"
if (project.hasProperty('remote')) {
commandLine = ['/usr/bin/ssh', remote] + commandLine
}
}
}
}
return project.exec(extendedAction)
}
public ExecResult execRemote(Closure closure) {
return this.execRemote(ConfigureUtil.configureUsing(closure));
}
}
@@ -82,7 +82,10 @@ abstract class KonanTest extends JavaExec {
"-ea",
*filesToCompile,
*moreArgs,
*project.globalArgs]
*project.globalTestArgs]
if (project.testTarget) {
args "-target", project.testTarget
}
standardOutput = log
errorOutput = log
super.exec()
@@ -162,7 +165,7 @@ abstract class KonanTest extends JavaExec {
def out = null
//TODO Add test timeout
ExecResult execResult = project.exec {
ExecResult execResult = project.execRemote {
commandLine exe
if (arguments != null) {
args arguments
@@ -210,6 +213,7 @@ class RunInteropKonanTest extends KonanTest {
void setInterop(String value) {
this.interop = value
this.interopConf = project.kotlinNativeInterop[value]
this.interopConf.target = project.testTarget
this.dependsOn(this.interopConf.genTask)
}
@@ -27,7 +27,8 @@ class NamedNativeInteropConfig implements Named {
private String defFile
private String pkg;
private String pkg
private String target
private List<String> compilerOpts = []
private List<String> headers;
@@ -47,6 +48,10 @@ class NamedNativeInteropConfig implements Named {
genTask.inputs.file(project.file(defFile))
}
void target(String value) {
target = value
}
void pkg(String value) {
pkg = value
}
@@ -191,7 +196,7 @@ class NamedNativeInteropConfig implements Named {
args "-natives:" + nativeLibsDir
args "-flavor:" + this.flavor
// Uncomment to debug.
//args "-verbose:true"
// args "-verbose:true"
if (defFile != null) {
args "-def:" + project.file(defFile)
@@ -205,6 +210,10 @@ class NamedNativeInteropConfig implements Named {
args "-linker:" + linker
}
if (target != null) {
args "-target:" + target
}
// TODO: the interop plugin should probably be reworked to execute clang from build scripts directly
environment['PATH'] = project.files(project.clangPath).asPath +
File.pathSeparator + environment['PATH']