forked from NationalSecurityAgency/ghidra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjavaTestProject.gradle
196 lines (163 loc) · 6.34 KB
/
javaTestProject.gradle
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
/*****************************************************************************************
This file is a "mix-in" gradle script that individual gradle projects that should be included
if this module has tests that should be included when running all the Ghidra tests.
A gradle project can add itself to the test run by including the following in its build.gradle
file:
apply from: "$rootProject.projectDir/gradle/support/javaTestProject.gradle"
*****************************************************************************************/
configurations {
jmockitAgent
}
dependencies {
jmockitAgent('org.jmockit:jmockit:1.44') {
exclude group: 'com.google.code.findbugs', module: 'jsr305'
}
}
test { t ->
forkEvery 1
initTestJVM(t, rootProject.ext.testRootDirName)
// WARNING! WATCH OUT !!
// WARNING! Since a single shared JVM instance is used, the first
// test and its ApplicationConfiguration will be used to initialize
// the class searching environment. This can have a negative impact
// on test results due to the inconsistent Application environment
// which may exist when all tests are run versus a single test.
//
// Based on this limitation, do not place tests that depend on integration
// base classes (eg: AbstractGhidraHeadlessIntegrationTest) in 'test'; they
// must go in 'test.slow'.
// Do not include suite classes; they trigger the tests in the suite to get run twice
// (once by normal jUnit and again when the suite runs).
excludes = ['**/*Suite*']
doFirst {
startTestTimer(t)
}
doLast {
endTestTimer(t)
}
}
task integrationTest (type: Test) { t ->
group "test"
dependsOn { project(":FunctionID").unpackFidDatabases }
testClassesDirs = files sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
// Do not include suite classes; they trigger the tests in the suite to get run twice
// (once by normal jUnit and again when the suite runs).
excludes = ['**/*Suite*']
// Enable if you want to force Gradle to launch a new JVM for each test.
forkEvery 1
initTestJVM(t, rootProject.ext.testRootDirName)
doFirst {
startTestTimer(t)
}
doLast {
endTestTimer(t)
}
}
task pcodeTest (type: Test) { t ->
group "pcodeTest"
dependsOn { project(":FunctionID").unpackFidDatabases }
testClassesDirs = files sourceSets.pcodeTest.output.classesDirs
classpath = sourceSets.pcodeTest.runtimeClasspath
// Enable if you want to force Gradle to launch a new JVM for each test.
forkEvery 1
initTestJVM(t, rootProject.ext.pcodeTestRootDirName)
doFirst {
startTestTimer(t)
}
doLast {
endTestTimer(t)
}
}
rootProject.unitTestReport {
reportOn this.project.test
}
rootProject.integrationTestReport {
reportOn this.project.integrationTest
}
rootProject.pcodeTestReport {
reportOn this.project.pcodeTest
}
rootProject.combinedTestReport {
reportOn this.project.test
reportOn this.project.integrationTest
}
/*********************************************************************************
* Initialize test task
*********************************************************************************/
def initTestJVM(Task task, String rootDirName) {
def testTempDir = file(rootTestDir).getAbsolutePath()
def testReportDir = file(reportDir).getAbsolutePath()
task.doFirst {
println "Test Machine Name: " + machineName
println "Root Test Dir: " + rootTestDir
println "Test Output Dir: " + testOutputDir
println "Test Temp Dir: " + testTempDir
println "Test Report Dir: " + testReportDir
println "Java Debug Port: " + debugPort
mkdir testTempDir
mkdir testOutputDir
}
// If false, testing will halt when an error is found.
task.ignoreFailures true
// If false, then tests are re-run every time, even if no code has changed.
task.outputs.upToDateWhen {false}
// Must set this to see System.out print statements.
task.testLogging.showStandardStreams = true
// Min/Max heap size. These are passed in.
task.minHeapSize xms
task.maxHeapSize xmx
// for jmockit; needs the javaagent option
// -javaagent:/path/to/jmockit.jar
task.doFirst {
def jmockitPath = configurations.jmockitAgent.singleFile
task.jvmArgs '-DupgradeProgramErrorMessage=' + upgradeProgramErrorMessage,
'-DupgradeTimeErrorMessage=' + upgradeTimeErrorMessage,
'-Dlog4j.configuration=' + logPropertiesUrl,
'-Dghidra.test.property.batch.mode=true',
'-Dghidra.test.property.parallel.mode=' + parallelMode,
'-Dghidra.test.property.output.dir=' + testOutputDir,
'-Dghidra.test.property.report.dir=' + testReportDir,
'-DSystemUtilities.isTesting=true',
'-Dmachine.name=' + machineName,
'-Djava.io.tmpdir=' + testTempDir,
'-Duser.data.dir=' + userHome + '/.ghidra/.ghidra-' + srcTreeName + '-Test',
'-Dcpu.core.override=8',
'-XX:ParallelGCThreads=8',
'-XX:+UseParallelGC',
'-Djava.awt.headless=false',
'-DDecompilerFunctionAnalyzer.enabled=false', // prevent long-winded analysis when testing (see DecompilerFunctionAnalyzer)
'-Dfile.encoding=UTF8',
'-Duser.country=US',
'-Duser.language=en',
'-Djdk.attach.allowAttachSelf',
'-javaagent:' + jmockitPath,
'-DLock.DEBUG=true',
'-Xdebug',
'-Xnoagent',
'-Djava.compiler=NONE',
'-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=' + debugPort
}
}
/*********************************************************************************
* Record and Print test task start time
*********************************************************************************/
def startTestTimer(Task task) {
project.ext.testStartTime = new Date()
println ":" + task.project.name + ":" + task.name + " started: " + testStartTime;
}
/*********************************************************************************
* Print test task end time and elapsed time
*********************************************************************************/
def endTestTimer(Task task) {
Date endTime = new Date();
println ":" + task.project.name + ":" + task.name + " ended: " + endTime;
long elapsedMS = endTime.getTime() - testStartTime.getTime();
long msPerMin = 60 * 1000;
long msPerHour = 60 * msPerMin;
long hrs = elapsedMS / msPerHour;
long mins = (elapsedMS - (hrs * msPerHour)) / msPerMin;
long secs = (elapsedMS - (hrs * msPerHour) - (mins * msPerMin)) / 1000;
println ":" + task.project.name + ":" + task.name + " elapsed time: " +
String.format("%d:%02d:%02d", hrs, mins, secs);
}