2020-01-27 12:05:34 -05:00
|
|
|
/*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership.
|
|
|
|
* The ASF licenses this file to You 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.
|
|
|
|
*/
|
|
|
|
|
2019-12-02 09:34:57 -05:00
|
|
|
import org.apache.tools.ant.taskdefs.condition.Os
|
2020-01-22 09:54:08 -05:00
|
|
|
import org.apache.tools.ant.types.Commandline
|
2019-12-02 09:34:57 -05:00
|
|
|
import org.gradle.api.tasks.testing.logging.*
|
2020-01-07 11:03:01 -05:00
|
|
|
import org.apache.lucene.gradle.ErrorReportingTestListener
|
2019-12-02 09:34:57 -05:00
|
|
|
|
2020-08-31 09:35:14 -04:00
|
|
|
def resources = scriptResources(buildscript)
|
2019-12-07 08:53:13 -05:00
|
|
|
def verboseModeHookInstalled = false
|
|
|
|
|
2019-12-02 09:34:57 -05:00
|
|
|
allprojects {
|
|
|
|
plugins.withType(JavaPlugin) {
|
|
|
|
project.ext {
|
2020-08-31 06:20:30 -04:00
|
|
|
// This array will collect all test options, including default values and option description.
|
|
|
|
// The actual values of these properties (defaults, project properties) are resolved lazily after evaluation
|
|
|
|
// completes.
|
|
|
|
// [propName: 'tests.foo', value: "bar", description: "Sets foo in tests."],
|
|
|
|
testOptions = [
|
|
|
|
// asserts, debug output.
|
|
|
|
[propName: 'tests.verbose', value: false, description: "Enables verbose mode (emits full test outputs immediately)."],
|
|
|
|
[propName: 'tests.workDir',
|
2023-03-06 13:17:37 -05:00
|
|
|
value: { -> project.relativePath(file("${buildDir}/tmp/tests-tmp")) },
|
2020-08-31 06:20:30 -04:00
|
|
|
description: "Working directory for forked test JVMs",
|
|
|
|
includeInReproLine: false
|
|
|
|
],
|
|
|
|
// JVM settings
|
|
|
|
[propName: 'tests.minheapsize', value: "256m", description: "Minimum heap size for test JVMs"],
|
|
|
|
[propName: 'tests.heapsize', value: "512m", description: "Heap size for test JVMs"],
|
|
|
|
// Test forks
|
|
|
|
[propName: 'tests.jvms',
|
|
|
|
value: { -> ((int) Math.max(1, Math.min(Runtime.runtime.availableProcessors() / 2.0, 4.0))) },
|
|
|
|
description: "Number of forked test JVMs"],
|
2023-09-18 08:30:53 -04:00
|
|
|
[propName: 'tests.haltonfailure',
|
|
|
|
value: true,
|
|
|
|
description: "Halt processing on test failure.",
|
|
|
|
includeInReproLine: false
|
|
|
|
],
|
2020-08-31 06:20:30 -04:00
|
|
|
[propName: 'tests.jvmargs',
|
2023-05-25 02:59:50 -04:00
|
|
|
value: { -> propertyOrEnvOrDefault("tests.jvmargs", "TEST_JVM_ARGS", isCIBuild ? "" : "-XX:TieredStopAtLevel=1 -XX:+UseParallelGC -XX:ActiveProcessorCount=1") },
|
2020-08-31 06:20:30 -04:00
|
|
|
description: "Arguments passed to each forked JVM."],
|
2021-10-25 08:51:11 -04:00
|
|
|
// Other settings.
|
|
|
|
[propName: 'tests.neverUpToDate', value: true,
|
|
|
|
description: "Make test tasks always fail the up-to-date checks (rerun) even if the inputs have not changed."],
|
2020-08-31 06:20:30 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
// Resolves test option's value.
|
|
|
|
resolvedTestOption = { propName ->
|
|
|
|
def option = testOptions.find { entry -> entry.propName == propName }
|
|
|
|
if (option == null) {
|
|
|
|
throw new GradleException("No such test option: " + propName)
|
|
|
|
}
|
|
|
|
return propertyOrDefault(option.propName, option.value)
|
|
|
|
}
|
|
|
|
|
2020-01-22 09:54:08 -05:00
|
|
|
testsCwd = file("${buildDir}/tmp/tests-cwd")
|
2020-08-31 06:20:30 -04:00
|
|
|
testsTmpDir = file(resolvedTestOption("tests.workDir"))
|
2021-03-08 08:59:08 -05:00
|
|
|
|
2021-03-18 06:04:45 -04:00
|
|
|
commonDir = project(":lucene").projectDir
|
2019-12-02 09:34:57 -05:00
|
|
|
}
|
|
|
|
|
2020-08-31 06:20:30 -04:00
|
|
|
def verboseMode = resolvedTestOption("tests.verbose").toBoolean()
|
|
|
|
|
2019-12-07 08:53:13 -05:00
|
|
|
// If we're running in verbose mode and:
|
|
|
|
// 1) worker count > 1
|
|
|
|
// 2) number of 'test' tasks in the build is > 1
|
|
|
|
// then the output would very likely be mangled on the
|
|
|
|
// console. Fail and let the user know what to do.
|
|
|
|
if (verboseMode && !verboseModeHookInstalled) {
|
|
|
|
verboseModeHookInstalled = true
|
|
|
|
if (gradle.startParameter.maxWorkerCount > 1) {
|
|
|
|
gradle.taskGraph.whenReady { graph ->
|
|
|
|
def testTasks = graph.allTasks.findAll { task -> task instanceof Test }
|
|
|
|
if (testTasks.size() > 1) {
|
|
|
|
throw new GradleException("Run your tests in verbose mode only with --max-workers=1 option passed to gradle.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-18 03:28:50 -04:00
|
|
|
tasks.withType(Test) {
|
2020-01-15 08:01:20 -05:00
|
|
|
ext {
|
2021-11-09 02:34:04 -05:00
|
|
|
testOutputsDir = file("${reports.junitXml.outputLocation.get()}/outputs")
|
2020-01-15 08:01:20 -05:00
|
|
|
}
|
|
|
|
|
2021-10-25 08:51:11 -04:00
|
|
|
// LUCENE-9660: Make it possible to always rerun tests, even if they're incrementally up-to-date.
|
|
|
|
if (resolvedTestOption("tests.neverUpToDate").toBoolean()) {
|
|
|
|
outputs.upToDateWhen { false }
|
|
|
|
}
|
|
|
|
|
2020-08-31 06:20:30 -04:00
|
|
|
maxParallelForks = resolvedTestOption("tests.jvms") as Integer
|
|
|
|
if (verboseMode && maxParallelForks != 1) {
|
|
|
|
logger.lifecycle("tests.jvm forced to 1 in verbose mode.")
|
2019-12-07 08:53:13 -05:00
|
|
|
maxParallelForks = 1
|
|
|
|
}
|
2019-12-02 09:34:57 -05:00
|
|
|
|
2020-01-22 09:54:08 -05:00
|
|
|
workingDir testsCwd
|
2019-12-02 09:34:57 -05:00
|
|
|
useJUnit()
|
|
|
|
|
2020-08-31 06:20:30 -04:00
|
|
|
minHeapSize = resolvedTestOption("tests.minheapsize")
|
|
|
|
maxHeapSize = resolvedTestOption("tests.heapsize")
|
|
|
|
|
|
|
|
ignoreFailures = resolvedTestOption("tests.haltonfailure").toBoolean() == false
|
2020-01-22 09:54:08 -05:00
|
|
|
|
2020-08-31 06:20:30 -04:00
|
|
|
jvmArgs Commandline.translateCommandline(resolvedTestOption("tests.jvmargs"))
|
2021-09-22 13:41:59 -04:00
|
|
|
|
|
|
|
// Up to JDK-15 we have to enforce --illegal-access=deny, because we want no code to access
|
|
|
|
// JDK internals; JDK-16 and later will default to deny, see https://openjdk.java.net/jeps/396:
|
|
|
|
if (rootProject.runtimeJavaVersion < JavaVersion.VERSION_16) {
|
|
|
|
jvmArgs '--illegal-access=deny'
|
|
|
|
}
|
2023-05-25 02:59:50 -04:00
|
|
|
|
2021-12-29 12:18:21 -05:00
|
|
|
// Lucene needs to optional modules at runtime, which we want to enforce for testing
|
|
|
|
// (if the runner JVM does not support them, it will fail tests):
|
|
|
|
jvmArgs '--add-modules', 'jdk.unsupported,jdk.management'
|
2019-12-02 09:34:57 -05:00
|
|
|
|
2023-05-25 02:59:50 -04:00
|
|
|
// Enable the vector incubator module on supported Java versions:
|
|
|
|
if (rootProject.vectorIncubatorJavaVersions.contains(rootProject.runtimeJavaVersion)) {
|
|
|
|
jvmArgs '--add-modules', 'jdk.incubator.vector'
|
|
|
|
}
|
|
|
|
|
2023-03-06 13:17:37 -05:00
|
|
|
def loggingConfigFile = layout.projectDirectory.file("${resources}/logging.properties")
|
|
|
|
def tempDir = layout.projectDirectory.dir(testsTmpDir.toString())
|
|
|
|
jvmArgumentProviders.add(
|
|
|
|
new LoggingFileArgumentProvider(
|
|
|
|
loggingConfigFile: loggingConfigFile,
|
|
|
|
tempDir: tempDir
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2019-12-02 09:34:57 -05:00
|
|
|
systemProperty 'java.awt.headless', 'true'
|
|
|
|
systemProperty 'jdk.map.althashing.threshold', '0'
|
|
|
|
|
|
|
|
if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
|
|
|
|
systemProperty 'java.security.egd', 'file:/dev/./urandom'
|
|
|
|
}
|
|
|
|
|
2019-12-06 05:55:53 -05:00
|
|
|
// jetty-related.
|
|
|
|
systemProperty 'jetty.testMode', '1'
|
|
|
|
systemProperty 'jetty.insecurerandom', '1'
|
|
|
|
|
|
|
|
// Turn jenkins blood red for hashmap bugs, even on jdk7
|
|
|
|
systemProperty 'jdk.map.althashing.threshold', '0'
|
|
|
|
|
2019-12-09 10:43:44 -05:00
|
|
|
// Pass these to RandomizedRunner so that it doesn't attempt to set them.
|
|
|
|
systemProperty 'junit4.childvm.count', '1'
|
|
|
|
systemProperty 'junit4.childvm.id', '0'
|
|
|
|
|
2019-12-02 09:34:57 -05:00
|
|
|
// Set up cwd and temp locations.
|
|
|
|
systemProperty("java.io.tmpdir", testsTmpDir)
|
|
|
|
doFirst {
|
2020-01-22 09:54:08 -05:00
|
|
|
testsCwd.mkdirs()
|
2019-12-02 09:34:57 -05:00
|
|
|
testsTmpDir.mkdirs()
|
|
|
|
}
|
|
|
|
|
2020-01-07 11:03:01 -05:00
|
|
|
// Disable HTML report generation. The reports are big and slow to generate.
|
2021-10-29 10:59:47 -04:00
|
|
|
reports.html.required = false
|
2020-01-07 11:03:01 -05:00
|
|
|
|
2019-12-02 09:34:57 -05:00
|
|
|
// Set up logging.
|
2020-01-08 05:38:34 -05:00
|
|
|
testLogging {
|
|
|
|
events TestLogEvent.FAILED
|
|
|
|
exceptionFormat TestExceptionFormat.FULL
|
|
|
|
showExceptions true
|
|
|
|
showCauses true
|
|
|
|
showStackTraces true
|
2020-01-27 06:09:04 -05:00
|
|
|
stackTraceFilters.clear()
|
2020-01-08 05:38:34 -05:00
|
|
|
showStandardStreams false
|
|
|
|
}
|
2020-01-08 04:55:07 -05:00
|
|
|
|
2021-12-26 12:18:24 -05:00
|
|
|
// Disable automatic test class detection, rely on class names only. This is needed for testing
|
|
|
|
// against JDKs where the bytecode is unparseable by Gradle, for example.
|
|
|
|
// We require all tests to start with Test*, this simplifies include patterns greatly.
|
|
|
|
scanForTestClasses = false
|
|
|
|
include '**/Test*.class'
|
|
|
|
exclude '**/*$*'
|
|
|
|
|
2020-01-08 05:38:34 -05:00
|
|
|
// Set up custom test output handler.
|
|
|
|
doFirst {
|
|
|
|
project.delete testOutputsDir
|
2019-12-02 09:34:57 -05:00
|
|
|
}
|
|
|
|
|
2020-01-08 05:38:34 -05:00
|
|
|
def spillDir = getTemporaryDir().toPath()
|
|
|
|
def listener = new ErrorReportingTestListener(test.testLogging, spillDir, testOutputsDir.toPath(), verboseMode)
|
|
|
|
addTestOutputListener(listener)
|
|
|
|
addTestListener(listener)
|
|
|
|
|
2019-12-02 09:34:57 -05:00
|
|
|
doFirst {
|
|
|
|
// Print some diagnostics about locations used.
|
2020-01-22 09:54:08 -05:00
|
|
|
logger.info("Test folders for {}: cwd={}, tmp={}", project.path, testsCwd, testsTmpDir)
|
2019-12-02 09:34:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-06 13:17:37 -05:00
|
|
|
|
|
|
|
class LoggingFileArgumentProvider implements CommandLineArgumentProvider {
|
|
|
|
@InputFile
|
|
|
|
@PathSensitive(PathSensitivity.RELATIVE)
|
|
|
|
RegularFile loggingConfigFile
|
|
|
|
|
|
|
|
@Internal
|
|
|
|
Directory tempDir
|
|
|
|
|
|
|
|
@Override
|
|
|
|
Iterable<String> asArguments() {
|
|
|
|
[
|
|
|
|
"-Djava.util.logging.config.file=${loggingConfigFile.getAsFile()}",
|
|
|
|
"-DtempDir=${tempDir.getAsFile()}"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|