File: performanceTest.gradle

package info (click to toggle)
gradle 4.4.1-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 85,104 kB
  • sloc: java: 319,724; xml: 14,356; cpp: 4,200; ansic: 1,025; sh: 300; makefile: 60; asm: 17; jsp: 17; objc: 10
file content (303 lines) | stat: -rw-r--r-- 10,534 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/*
 * Copyright 2016 the original author or authors.
 *
 * 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.
 */


import org.gradle.testing.DistributedPerformanceTest
import org.gradle.testing.PerformanceTest
import org.gradle.testing.performance.generator.tasks.JavaExecProjectGeneratorTask
import org.gradle.testing.performance.generator.tasks.JvmProjectGeneratorTask
import org.gradle.testing.performance.generator.tasks.ProjectGeneratorTask
import org.gradle.testing.performance.generator.tasks.RemoteProject

apply plugin: 'java'

sourceSets {
    performanceTest {
        compileClasspath += main.output + test.output
        runtimeClasspath += main.output + test.output
    }
}

configurations {
    performanceTestCompile.extendsFrom testCompile
    performanceTestRuntime.extendsFrom testRuntime
    partialDistribution.extendsFrom performanceTestRuntimeClasspath
    junit
}

dependencies {
    performanceTestCompile project(":internalPerformanceTesting")

    //so that implicit help tasks are available:
    performanceTestRuntime project(':diagnostics')

    performanceTestRuntime project(':buildInit')
    performanceTestRuntime project(':buildCacheHttp')
    performanceTestRuntime project(':codeQuality')
    performanceTestRuntime project(':ide')
    performanceTestRuntime project(':maven')
    performanceTestRuntime project(':testingNative')
    performanceTestRuntime project(':toolingApiBuilders')

    junit 'junit:junit:4.12'
}

task checkNoIdenticalBuildFiles {
    doLast {
        def files = [:].withDefault { [] }
        buildDir.eachFileRecurse {
            if (it.name.endsWith('.gradle')) {
                def hash = HashUtil.createHash(it, 'sha1').asHexString()
                files[hash] << it
            }
        }
        files.each { hash, candidates ->
            if (candidates.size()>1) {
                println "Duplicate build files found for hash '$hash' : $candidates"
            }
        }
    }
}

tasks.withType(ProjectGeneratorTask) {
    group = 'Project setup'
    if(project.hasProperty("maxProjects")) {
        projects = maxProjects as Integer
    }
}

tasks.withType(JvmProjectGeneratorTask) {
    testDependencies = configurations.junit
}

task prepareSamples {
    dependsOn tasks.withType(ProjectGeneratorTask)
    dependsOn tasks.withType(RemoteProject)
    dependsOn tasks.withType(JavaExecProjectGeneratorTask)
    group = "Project Setup"
    description = "Generates all sample projects for automated performance tests"
}

task cleanSamples(type: Delete) {
    delete {tasks.withType(ProjectGeneratorTask)*.destDir}
    delete {tasks.withType(RemoteProject)*.outputDirectory}
    delete {tasks.withType(JavaExecProjectGeneratorTask)*.outputs}
}

def withPerformanceDb = { task ->
    def urlProperty = "org.gradle.performance.db.url"
    def url = project.findProperty(urlProperty)
    if (url) {
        task.systemProperty urlProperty, url
    }
    def usernameProperty = "org.gradle.performance.db.username"
    def username = project.findProperty(usernameProperty)
    if (username) {
        task.systemProperty usernameProperty, username
    }
    def passwordProperty = "org.gradle.performance.db.password"
    def password = project.findProperty(passwordProperty)
    if (password) {
        task.systemProperty passwordProperty, password
    }
}

ext.performanceReportTasks = tasks.withType(PerformanceReport)
performanceReportTasks.all(withPerformanceDb)

task performanceReport(type: PerformanceReport) {
    classpath = sourceSets.performanceTest.runtimeClasspath
    resultStoreClass = "org.gradle.performance.results.AllResultsStore"
    reportDir = new File(buildDir, "performance-tests/report")
    outputs.upToDateWhen { false }
}

ext.performanceTestTasks = tasks.withType(PerformanceTest)

performanceTestTasks.all { PerformanceTest task ->
    withPerformanceDb(task)
    classpath = sourceSets.performanceTest.runtimeClasspath
    dependsOn prepareSamples
    mustRunAfter tasks.withType(ProjectGeneratorTask)
    mustRunAfter tasks.withType(RemoteProject)
    mustRunAfter tasks.withType(JavaExecProjectGeneratorTask)
    requiresBinZip = true
    requiresLibsRepo = true

    finalizedBy performanceReport

    project.task("clean${task.name.capitalize()}", type: Delete) {
        delete task.outputs
        dependsOn cleanPerformanceReport
    }

    if (project.findProperty('org.gradle.performance.baselines')) {
        systemProperty 'org.gradle.performance.baselines', project.getProperty('org.gradle.performance.baselines')
    }

    maxParallelForks = 1

    doFirst {
        if (task.channel) {
            performanceReport.systemProperty 'org.gradle.performance.execution.channel', task.channel
        }
    }
}

task performanceTest(type: PerformanceTest) {
    options {
        excludeCategories 'org.gradle.performance.categories.PerformanceExperiment'
    }
}

task performanceExperiment(type: PerformanceTest) {
    options {
        includeCategories 'org.gradle.performance.categories.PerformanceExperiment'
    }
}

task fullPerformanceTest(type: PerformanceTest) {
}

task performanceAdhocTest(type: PerformanceTest) {
    systemProperty "org.gradle.performance.db.url", "jdbc:h2:./build/database"
    channel = "adhoc"
}

tasks.withType(DistributedPerformanceTest) {
    scenarioList = file("$buildDir/performance-tests/scenario-list.csv")
    scenarioReport = file("$buildDir/performance-tests/scenario-report.html")
    buildTypeId = project.findProperty("org.gradle.performance.buildTypeId")
    workerTestTaskName = project.findProperty("org.gradle.performance.workerTestTaskName")?:'fullPerformanceTest'
    coordinatorBuildId = project.findProperty("org.gradle.performance.coordinatorBuildId")
    branchName = project.findProperty("org.gradle.performance.branchName")
    teamCityUrl = "https://builds.gradle.org/"
    teamCityUsername = project.findProperty("teamCityUsername")
    teamCityPassword = project.findProperty("teamCityPassword")
    afterEvaluate { p ->
      if (branchName) {
        channel = channel + "-" + branchName
      }
    }
}

task distributedPerformanceTest(type: DistributedPerformanceTest) {
    options {
        excludeCategories 'org.gradle.performance.categories.PerformanceExperiment'
    }
    channel = 'commits'
}

task distributedPerformanceExperiment(type: DistributedPerformanceTest) {
    options {
        includeCategories 'org.gradle.performance.categories.PerformanceExperiment'
    }
    channel = 'experiments'
}

task distributedFullPerformanceTest(type: DistributedPerformanceTest) {
    baselines = ['1.1', '1.12', '2.0', '2.1', '2.4', '2.9', '2.12', '2.14.1', 'last']
    checks = 'none'
    channel = 'historical'
}

configure([performanceTest, performanceExperiment, fullPerformanceTest, performanceAdhocTest]) {
    group = 'verification'

    if (project.hasProperty('org.gradle.performance.use_yourkit')) {
        testLogging.showStandardStreams = true
        systemProperties['org.gradle.performance.use_yourkit'] = '1'
        outputs.upToDateWhen { false }
    }
    if (project.hasProperty('org.gradle.performance.honestprofiler')) {
        systemProperties['org.gradle.performance.honestprofiler'] = '1'
    }
    if (project.hasProperty('performanceTest.verbose')) {
        testLogging.showStandardStreams = true
    }
}

plugins.withType(org.gradle.plugins.ide.eclipse.EclipsePlugin) {
    eclipse {
        classpath {
            plusConfigurations.add(configurations.performanceTestCompile)
            plusConfigurations.add(configurations.performanceTestRuntime)
        }
    }
}

plugins.withType(org.gradle.plugins.ide.idea.IdeaPlugin) {
    idea {
        module {
            testSourceDirs += sourceSets.performanceTest.groovy.srcDirs
            testSourceDirs += sourceSets.performanceTest.resources.srcDirs
            scopes.TEST.plus.add(configurations.performanceTestCompile)
            scopes.TEST.plus.add(configurations.performanceTestRuntime)
        }
    }
}

class PerformanceReport extends JavaExec {
    @Input
    String resultStoreClass
    @OutputDirectory
    File reportDir

    @TaskAction
    public void exec() {
        main = "org.gradle.performance.results.ReportGenerator"
        args = [resultStoreClass, reportDir.path]
        super.exec();
    }
}

tasks.withType(ProjectGeneratorTask) {
    sharedTemplateDirectory = project.findProject(':internalPerformanceTesting').file('src/templates')
}

// add task that zips the junit xml test report files to a zip file
// this file can be used to combine the test reports of the distributed test runs into a single report in the coordinator
tasks.withType(PerformanceTest) { task ->
    if(!(task instanceof DistributedPerformanceTest)) {
        def junitXmlDir = task.reports.junitXml.destination
        def testResultsZipTask = tasks.create(name: "${task.name}ResultsZip", type: org.gradle.api.tasks.bundling.Zip) {
            from(junitXmlDir) {
                include '**/TEST-*.xml'
                includeEmptyDirs = false
                eachFile { copyDetails ->
                    try {
                        def testsuite = new groovy.util.XmlSlurper().parse(copyDetails.file)
                        // skip files where all tests were skipped
                        if (testsuite.@tests.text() == testsuite.@skipped.text()) {
                            copyDetails.exclude()
                        }
                    } catch (e) {
                        copyDetails.exclude()
                    }
                }
            }
            from(task.debugArtifactsDirectory)
            destinationDir = buildDir
            archiveName = "test-results-${junitXmlDir.name}.zip"
        }
        task.finalizedBy testResultsZipTask

        def cleanTestResultsZipTask = tasks.create(name: "clean${testResultsZipTask.name.capitalize()}", type: Delete) {
            delete testResultsZipTask.archivePath
        }
        tasks.getByName("clean${task.name.capitalize()}").dependsOn cleanTestResultsZipTask
    }
}