forked from square/okhttp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial steps towards running tests in Graalvm (square#6313)
I want to confirm all of OkHttp works with Graalvm, and I'm hoping to demonstrate that by getting the entire test suite running inside Graalvm. square#6296
- Loading branch information
1 parent
27b52ab
commit 924bd08
Showing
4 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
Native Image Tests | ||
================== | ||
|
||
This executes OkHttp's test suite inside a Graalvm image. | ||
|
||
Seeding Graalvm Config | ||
---------------------- | ||
|
||
This isn't yet integrated into the Graalvm Gradle plugin, so you'll need to install your own | ||
Graalvm and edit `build.gradle` to set its location. | ||
|
||
``` | ||
def graalHome = "/Library/Java/JavaVirtualMachines/graalvm-ce-java11-20.2.0/Contents/Home" | ||
``` | ||
|
||
The task runs tests in the JVM, collecting information about which classes require reflection | ||
metadata. This includes the test classes and some parts of the JUnit framework. | ||
|
||
``` | ||
./gradlew --info native-image-tests:seedGraalvmConfig | ||
``` | ||
|
||
This will create a directory of metadata: | ||
|
||
okhttp | ||
'- native-image-tests | ||
'- build | ||
'- graalvm | ||
'- resources | ||
'- META-INF | ||
'- native-image | ||
|- jni-config.json | ||
|- proxy-config.json | ||
|- reflect-config.json | ||
'- resource-config.json | ||
|
||
Build the Native Image | ||
---------------------- | ||
|
||
Compile the classes and metadata into a Graalvm native image. | ||
|
||
``` | ||
./gradlew --info native-image-tests:nativeImage | ||
``` | ||
|
||
|
||
Execute | ||
------- | ||
|
||
The native image runs JUnit 5's `ConsoleLauncher`. | ||
|
||
``` | ||
./native-image-tests/build/graal/ConsoleLauncher --select-class okhttp3.SampleTest | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
plugins { | ||
id "com.palantir.graal" version "0.7.1" | ||
} | ||
|
||
dependencies { | ||
implementation deps.assertj | ||
implementation "org.junit.jupiter:junit-jupiter-api:5.7.0" | ||
implementation "org.junit.jupiter:junit-jupiter-engine:5.7.0" | ||
implementation "org.junit.platform:junit-platform-console:1.7.0" | ||
|
||
compileOnly deps.jsr305 | ||
} | ||
|
||
animalsniffer { | ||
ignoreFailures = true | ||
} | ||
|
||
def graalHome = "/Library/Java/JavaVirtualMachines/graalvm-ce-java11-20.2.0/Contents/Home" | ||
def graalvmResources = project.file("$buildDir/graalvm/resources") | ||
def graalvmConfig = project.file("$graalvmResources/META-INF/native-image") | ||
graalvmConfig.mkdirs() | ||
|
||
sourceSets { | ||
main.resources.srcDirs += graalvmResources | ||
} | ||
|
||
task seedGraalvmConfig(type: Exec) { | ||
dependsOn("classes") | ||
commandLine( | ||
"$graalHome/bin/java", | ||
"-agentlib:native-image-agent=config-output-dir=$graalvmConfig", | ||
"-classpath", sourceSets.main.runtimeClasspath.getAsPath(), | ||
"org.junit.platform.console.ConsoleLauncher", | ||
"--select-class", "okhttp3.SampleTest" | ||
) | ||
} | ||
|
||
graal { | ||
mainClass "org.junit.platform.console.ConsoleLauncher" | ||
outputName "ConsoleLauncher" | ||
graalVersion "20.2.0" | ||
javaVersion "11" | ||
|
||
option "--enable-https" | ||
option "--no-fallback" | ||
option "--allow-incomplete-classpath" | ||
option "--report-unsupported-elements-at-runtime" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright (C) 2020 Square, Inc. | ||
* | ||
* 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 okhttp3 | ||
|
||
import org.assertj.core.api.AssertionsForClassTypes.assertThat | ||
import org.junit.jupiter.api.Test | ||
|
||
class SampleTest { | ||
@Test | ||
fun failingTest() { | ||
assertThat("hello").isEqualTo("goodbye") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters