Add kotlinx.coroutines tests and run them internally
This CL will include all needed dependencies and run smoke tests on
the first batch of kotlinx.coroutines test. Running r8 on base
dependencies will be done in later.
Bug: 156012389
Bug: 157023682
Change-Id: I5b89e5d7a0b05bbf576cc637a0b44289c473d289
diff --git a/.gitignore b/.gitignore
index ec03160..0629bac 100644
--- a/.gitignore
+++ b/.gitignore
@@ -98,6 +98,8 @@
third_party/kotlin/kotlin-compiler-1.3.41
third_party/kotlin/kotlin-compiler-1.3.72.tar.gz
third_party/kotlin/kotlin-compiler-1.3.72
+third_party/kotlinx-coroutines-1.3.6.tar.gz
+third_party/kotlinx-coroutines-1.3.6
third_party/nest/*
third_party/openjdk/desugar_jdk_libs
third_party/openjdk/desugar_jdk_libs.tar.gz
diff --git a/build.gradle b/build.gradle
index 90ad4ab..338df88 100644
--- a/build.gradle
+++ b/build.gradle
@@ -327,6 +327,7 @@
"kotlin/kotlin-compiler-1.3.11",
"kotlin/kotlin-compiler-1.3.41",
"kotlin/kotlin-compiler-1.3.72",
+ "kotlinx-coroutines-1.3.6",
"openjdk/openjdk-rt-1.8",
"openjdk/desugar_jdk_libs",
"openjdk/jdk-11-test",
diff --git a/src/test/java/com/android/tools/r8/KotlinCompilerTool.java b/src/test/java/com/android/tools/r8/KotlinCompilerTool.java
index ca9abd4..9a36a04 100644
--- a/src/test/java/com/android/tools/r8/KotlinCompilerTool.java
+++ b/src/test/java/com/android/tools/r8/KotlinCompilerTool.java
@@ -19,6 +19,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.rules.TemporaryFolder;
@@ -57,6 +58,7 @@
private final KotlinTargetVersion targetVersion;
private final List<Path> sources = new ArrayList<>();
private final List<Path> classpath = new ArrayList<>();
+ private final List<String> additionalArguments = new ArrayList<>();
private boolean useJvmAssertions;
private Path output = null;
@@ -84,6 +86,11 @@
return new KotlinCompilerTool(jdk, state, kotlinCompiler, kotlinTargetVersion);
}
+ public KotlinCompilerTool addArguments(String... arguments) {
+ Collections.addAll(additionalArguments, arguments);
+ return this;
+ }
+
public KotlinCompilerTool addSourceFiles(Path... files) {
return addSourceFiles(Arrays.asList(files));
}
@@ -181,6 +188,7 @@
.map(Path::toString)
.collect(Collectors.joining(isWindows() ? ";" : ":")));
}
+ cmdline.addAll(additionalArguments);
ProcessBuilder builder = new ProcessBuilder(cmdline);
return ToolHelper.runProcess(builder);
}
diff --git a/src/test/java/com/android/tools/r8/kotlin/coroutines/KotlinxCoroutinesTestRunner.java b/src/test/java/com/android/tools/r8/kotlin/coroutines/KotlinxCoroutinesTestRunner.java
new file mode 100644
index 0000000..904f69f
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/kotlin/coroutines/KotlinxCoroutinesTestRunner.java
@@ -0,0 +1,102 @@
+// Copyright (c) 2020, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+package com.android.tools.r8.kotlin.coroutines;
+
+import static com.android.tools.r8.KotlinCompilerTool.KOTLINC;
+import static org.junit.Assert.assertEquals;
+
+import com.android.tools.r8.KotlinTestBase;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.ToolHelper;
+import com.android.tools.r8.ToolHelper.KotlinTargetVersion;
+import com.android.tools.r8.ToolHelper.ProcessResult;
+import com.android.tools.r8.utils.ZipUtils;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Sets;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class KotlinxCoroutinesTestRunner extends KotlinTestBase {
+
+ private static final String PKG = "kotlinx-coroutines-1.3.6";
+ private static final Path BASE_LIBRARY =
+ Paths.get(ToolHelper.THIRD_PARTY_DIR, PKG, "deps_all-1.3.6-SNAPSHOT.jar");
+ private static final Path TEST_SOURCES =
+ Paths.get(ToolHelper.THIRD_PARTY_DIR, PKG, "kotlinx-coroutines-test-test-sources");
+ private static final List<Path> DEPENDENCIES =
+ ImmutableList.of(
+ Paths.get(ToolHelper.THIRD_PARTY_DIR, PKG, "atomicfu-0.14.3.jar"),
+ Paths.get(ToolHelper.THIRD_PARTY_DIR, PKG, "hamcrest-core-1.3.jar"),
+ Paths.get(ToolHelper.THIRD_PARTY_DIR, PKG, "junit-4.13.jar"),
+ Paths.get(ToolHelper.THIRD_PARTY_DIR, PKG, "kotlin-test-1.3.72.jar"),
+ Paths.get(ToolHelper.THIRD_PARTY_DIR, PKG, "kotlin-test-junit-1.3.71.jar"),
+ Paths.get(ToolHelper.THIRD_PARTY_DIR, PKG, "kotlinx.coroutines.testbase.jar"),
+ Paths.get(ToolHelper.THIRD_PARTY_DIR, PKG, "kotlinx.coroutines.test.main.jar"));
+
+ // Tests that do not run correctly in general - that is these tests are expected to fail always.
+ private Set<String> notWorkingTests =
+ Sets.newHashSet("kotlinx.coroutines.test.TestDispatchersTest");
+
+ @Parameterized.Parameters(name = "{0} target: {1}")
+ public static Collection<Object[]> data() {
+ return buildParameters(
+ getTestParameters().withCfRuntimes().build(), KotlinTargetVersion.values());
+ }
+
+ private final TestParameters parameters;
+
+ public KotlinxCoroutinesTestRunner(TestParameters parameters, KotlinTargetVersion targetVersion) {
+ super(targetVersion);
+ this.parameters = parameters;
+ }
+
+ @Test
+ public void runKotlinxCoroutinesTests_smoke() throws Exception {
+ Path baseJar =
+ kotlinc(KOTLINC, targetVersion)
+ .addArguments(
+ "-Xuse-experimental=kotlinx.coroutines.InternalCoroutinesApi",
+ "-Xuse-experimental=kotlinx.coroutines.ObsoleteCoroutinesApi",
+ "-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi")
+ .addClasspathFiles(DEPENDENCIES)
+ .addClasspathFiles(BASE_LIBRARY)
+ .addSourceFiles(TEST_SOURCES)
+ .compile();
+ runTestsInJar(baseJar, BASE_LIBRARY);
+ }
+
+ private void runTestsInJar(Path testJar, Path deps) throws Exception {
+ List<Path> dependencies = new ArrayList<>(DEPENDENCIES);
+ dependencies.add(deps);
+ dependencies.add(testJar);
+ ZipUtils.iter(
+ testJar.toString(),
+ (entry, input) -> {
+ if (!entry.isDirectory() && entry.getName().endsWith("Test.class")) {
+ runTest(dependencies, entry.getName());
+ }
+ });
+ }
+
+ private void runTest(List<Path> dependencies, String name) throws IOException {
+ String testName = name.replace("/", ".").replace(".class", "");
+ if (notWorkingTests.contains(testName)) {
+ return;
+ }
+ ProcessResult processResult =
+ ToolHelper.runJava(
+ parameters.getRuntime().asCf(), dependencies, "org.junit.runner.JUnitCore", testName);
+ assertEquals(0, processResult.exitCode);
+ }
+}
diff --git a/third_party/kotlinx-coroutines-1.3.6.tar.gz.sha1 b/third_party/kotlinx-coroutines-1.3.6.tar.gz.sha1
new file mode 100644
index 0000000..6b4a3b8
--- /dev/null
+++ b/third_party/kotlinx-coroutines-1.3.6.tar.gz.sha1
@@ -0,0 +1 @@
+fe2b5c46bec807d11fcbd5572f9f7ba9d755cefd
\ No newline at end of file