Skip to content

Commit f36b4ae

Browse files
committed
Add some guidance for running Java debugger
This finishes wiring up the TEST_JAVA_ARGS CMake variable to allow builders to override the JVM flags during unit test runs. We can then use that to instantiate a remote debug server as a workaround for debugging ACCP.
1 parent cefeb1e commit f36b4ae

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

DEVELOPMENT-GUIDE.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,27 @@ So, when you are in a critical region there are exceedingly few operations you c
191191
Essentially, all you can do is methods which manipulate your critical region until you get out of it.
192192
It is **extremely important** that you do not allocate *any* Java memory (such as creating Java objects, like a Java Exception), call *any* Java methods (which you shouldn't be doing anyway), or take any actions which may block.
193193
It is also **very important** that you don't spend too much time (more than about a millisecond) in a critical region.
194-
If you are concerned that an operation is not reasonably time-bounded, you should probably be sure to release the critical region on a regular basis to ensure the JVM has the opportunity to do needed memory management. (This isn't always achievable when everything is happening within a single atomic cryptographic operation.)
194+
If you are concerned that an operation is not reasonably time-bounded, you should probably be sure to release the critical region on a regular basis to ensure the JVM has the opportunity to do needed memory management. (This isn't always achievable when everything is happening within a single atomic cryptographic operation.)
195+
196+
# Java Debugger Support
197+
Due to ACCP's unconventional build system, IDEs are not able to automatically configure, run, and debug the unit tests.
198+
This is largely because of how we use of Gradle/CMake to run the unit tests via the JUnit CLI which allows us to
199+
incorporate the natively compiled portion of the library. A simple workaround is to use the singleTest task along with
200+
JVM arguments to start a remote Java debugger session. This then allows you to connect and debug your test in the IDE.
201+
202+
```
203+
# 1. Create a new Run/Debug Configuration for "Remote JVM Debug" in IntelliJ or the equivalent for your IDE.
204+
205+
# 2. Launch your test target using the singlelTest target. n.b. Suspend is set to y to break immediately.
206+
TEST_CLASS=com.amazon.corretto.crypto.provider.test.KeyGeneratorTest
207+
./gradlew \
208+
-DTEST_JAVA_ARGS='-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005' \
209+
-DSINGLE_TEST=${TEST_CLASS} \
210+
singleTest
211+
212+
# 3. Wait for the server to start listening.
213+
...
214+
Listening for transport dt_socket at address: 5005
215+
216+
# 4. Set a breakpoint in the IDE and connect to the JVM debug server.
217+
```

build.gradle

+3-5
Original file line numberDiff line numberDiff line change
@@ -341,29 +341,27 @@ task executeCmake(type: Exec) {
341341
if (isExperimentalFips) {
342342
args '-DEXPERIMENTAL_FIPS=ON'
343343
}
344-
345344
if (prebuiltJar != null) {
346345
args '-DSIGNED_JAR=' + prebuiltJar
347346
println "Using SIGNED_JAR=${prebuiltJar}"
348347
}
349-
350348
if (System.properties['JAVA_HOME'] != null) {
351349
args '-DJAVA_HOME=' + System.properties['JAVA_HOME']
352350
}
353-
354351
if (System.properties['TEST_JAVA_HOME'] != null) {
355352
args '-DTEST_JAVA_HOME=' + System.properties['TEST_JAVA_HOME']
356353
}
357354
if (System.properties['TEST_JAVA_MAJOR_VERSION'] != null) {
358355
args '-DTEST_JAVA_MAJOR_VERSION=' + System.properties['TEST_JAVA_MAJOR_VERSION']
359356
}
357+
if (System.properties['TEST_JAVA_ARGS'] != null) {
358+
args '-DTEST_JAVA_ARGS=' + System.properties['TEST_JAVA_ARGS']
359+
}
360360
if (System.properties['SINGLE_TEST'] != null) {
361361
args '-DSINGLE_TEST=' + System.properties['SINGLE_TEST']
362-
363362
}
364363
if (System.properties['USE_CLANG_TIDY'] != null) {
365364
args '-DUSE_CLANG_TIDY=' + System.properties['USE_CLANG_TIDY']
366-
367365
}
368366
args projectDir
369367
}

0 commit comments

Comments
 (0)