Morten Krogh-Jespersen | 568c0f5 | 2023-08-09 15:25:07 +0200 | [diff] [blame] | 1 | // Copyright (c) 2023, the R8 project authors. Please see the AUTHORS file |
| 2 | // for details. All rights reserved. Use of this source code is governed by a |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | |
| 5 | import org.gradle.api.tasks.testing.Test |
Rico Wind | c1f418d | 2023-08-29 15:16:24 +0200 | [diff] [blame^] | 6 | import org.gradle.api.tasks.testing.TestListener |
| 7 | import org.gradle.api.tasks.testing.TestDescriptor |
| 8 | import org.gradle.api.tasks.testing.TestResult |
Morten Krogh-Jespersen | 568c0f5 | 2023-08-09 15:25:07 +0200 | [diff] [blame] | 9 | |
| 10 | class TestConfigurationHelper { |
| 11 | |
| 12 | companion object { |
| 13 | |
| 14 | fun setupTestTask(test: Test) { |
| 15 | val project = test.project |
| 16 | test.systemProperty("USE_NEW_GRADLE_SETUP", "true") |
| 17 | if (project.hasProperty("kotlin_compiler_dev")) { |
| 18 | test.systemProperty("com.android.tools.r8.kotlincompilerdev", "1") |
| 19 | } |
| 20 | |
| 21 | if (project.hasProperty("kotlin_compiler_old")) { |
| 22 | test.systemProperty("com.android.tools.r8.kotlincompilerold", "1") |
| 23 | } |
| 24 | |
| 25 | if (project.hasProperty("dex_vm") |
| 26 | && project.property("dex_vm") != "default") { |
| 27 | println("NOTE: Running with non default vm: " + project.property("dex_vm")) |
| 28 | test.systemProperty("dex_vm", project.property("dex_vm")!!) |
| 29 | } |
| 30 | |
| 31 | // Forward runtime configurations for test parameters. |
| 32 | if (project.hasProperty("runtimes")) { |
| 33 | println("NOTE: Running with runtimes: " + project.property("runtimes")) |
| 34 | test.systemProperty("runtimes", project.property("runtimes")!!) |
| 35 | } |
| 36 | |
| 37 | if (project.hasProperty("art_profile_rewriting_completeness_check")) { |
| 38 | test.systemProperty( |
| 39 | "com.android.tools.r8.artprofilerewritingcompletenesscheck", |
| 40 | project.property("art_profile_rewriting_completeness_check")!!) |
| 41 | } |
| 42 | |
| 43 | if (project.hasProperty("disable_assertions")) { |
| 44 | test.enableAssertions = false |
| 45 | } |
| 46 | |
| 47 | // Forward project properties into system properties. |
| 48 | listOf( |
| 49 | "slow_tests", |
| 50 | "desugar_jdk_json_dir", |
| 51 | "desugar_jdk_libs", |
| 52 | "test_dir", |
| 53 | "command_cache_dir").forEach { |
| 54 | if (project.hasProperty(it)) { |
| 55 | project.property(it)?.let { v -> test.systemProperty("slow_tests", v) } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | if (project.hasProperty("no_internal")) { |
| 60 | test.exclude("com/android/tools/r8/internal/**") |
| 61 | } |
| 62 | if (project.hasProperty("only_internal")) { |
| 63 | test.include("com/android/tools/r8/internal/**") |
| 64 | } |
| 65 | if (project.hasProperty("no_arttests")) { |
| 66 | test.exclude("com/android/tools/r8/art/**") |
| 67 | } |
| 68 | |
| 69 | if (project.hasProperty("test_xmx")) { |
| 70 | test.maxHeapSize = project.property("test_xmx")!!.toString() |
| 71 | } else { |
| 72 | test.maxHeapSize = "4G" |
| 73 | } |
| 74 | |
Rico Wind | c1f418d | 2023-08-29 15:16:24 +0200 | [diff] [blame^] | 75 | if (project.hasProperty("one_line_per_test")) { |
| 76 | test.addTestListener(object: TestListener { |
| 77 | override fun beforeSuite(desc: TestDescriptor?) { } |
| 78 | override fun afterSuite(desc: TestDescriptor?, result: TestResult?) { } |
| 79 | override fun beforeTest(desc: TestDescriptor?) { |
| 80 | println("Start executing ${desc}") |
| 81 | } |
| 82 | override fun afterTest(desc: TestDescriptor?, result: TestResult?) { |
| 83 | println("Done executing ${desc} with result: ${result?.resultType}") |
| 84 | } |
| 85 | }) |
| 86 | } |
| 87 | |
Morten Krogh-Jespersen | 568c0f5 | 2023-08-09 15:25:07 +0200 | [diff] [blame] | 88 | val userDefinedCoresPerFork = System.getenv("R8_GRADLE_CORES_PER_FORK") |
| 89 | val processors = Runtime.getRuntime().availableProcessors() |
| 90 | // See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html. |
Morten Krogh-Jespersen | f857ed8 | 2023-08-10 12:56:42 +0200 | [diff] [blame] | 91 | if (!userDefinedCoresPerFork.isNullOrEmpty()) { |
Morten Krogh-Jespersen | 568c0f5 | 2023-08-09 15:25:07 +0200 | [diff] [blame] | 92 | test.maxParallelForks = processors.div(userDefinedCoresPerFork.toInt()) |
| 93 | } else { |
| 94 | // On work machines this seems to give the best test execution time (without freezing). |
| 95 | test.maxParallelForks = processors.div(3) |
| 96 | // On low cpu count machines (bots) we under subscribe, so increase the count. |
Rico Wind | c1f418d | 2023-08-29 15:16:24 +0200 | [diff] [blame^] | 97 | if (processors == 32) { |
| 98 | test.maxParallelForks = 15 |
Morten Krogh-Jespersen | 568c0f5 | 2023-08-09 15:25:07 +0200 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | } |