-
Notifications
You must be signed in to change notification settings - Fork 12
Add testProcess{Config} task to accept user options #581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
zhengyu123
wants to merge
10
commits into
main
Choose a base branch
from
zgu/test_cmd_opts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
42d4d54
Create testProcess{Config} task that can pass command line profiler.o…
zhengyu123 6f5c7ba
Cleanup
zhengyu123 a13c32a
Fix
zhengyu123 0a80e41
Merge branch 'main' into zgu/test_cmd_opts
zhengyu123 710ac93
Fix
zhengyu123 9b9d36e
Merge branch 'main' into zgu/test_cmd_opts
zhengyu123 dff76a3
Merge branch 'main' into zgu/test_cmd_opts
zhengyu123 9e9d6a0
Fix review comments
zhengyu123 1d5a380
Merge branch 'zgu/test_cmd_opts' of github.com:DataDog/java-profiler …
zhengyu123 15dbbf7
Merge branch 'main' into zgu/test_cmd_opts
zhengyu123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -429,6 +429,116 @@ class ProfilerTestPlugin : Plugin<Project> { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Create Exec-based test task that always runs in a separate process. | ||
| * Available on all platforms. Supports -Pprofiler.options for overriding profiler settings. | ||
| * Task name: testProcess<Config> (e.g., testProcessDebug, testProcessRelease) | ||
| */ | ||
| private fun createProcessTestTask( | ||
| project: Project, | ||
| extension: ProfilerTestExtension, | ||
| testConfig: TestTaskConfiguration, | ||
| testCfg: Configuration, | ||
| sourceSets: SourceSetContainer | ||
| ) { | ||
| val taskName = "testProcess${testConfig.configName.replaceFirstChar { it.uppercase() }}" | ||
| project.tasks.register(taskName, Exec::class.java) { | ||
| val execTask = this | ||
| execTask.description = "Runs tests in separate process with ${testConfig.configName} library (supports -Pprofiler.options)" | ||
| execTask.group = "verification" | ||
| execTask.onlyIf { testConfig.isActive && !project.hasProperty("skip-tests") } | ||
|
|
||
| // Dependencies | ||
| execTask.dependsOn(project.tasks.named("compileTestJava")) | ||
| execTask.dependsOn(testCfg) | ||
| execTask.dependsOn(sourceSets.getByName("test").output) | ||
|
|
||
| // Configure at execution time to capture properties | ||
| execTask.doFirst { | ||
| execTask.executable = PlatformUtils.testJavaExecutable() | ||
|
|
||
| val allArgs = mutableListOf<String>() | ||
|
|
||
| // JVM args | ||
| allArgs.addAll(testConfig.standardJvmArgs) | ||
| // Version-gated at execution time, when the real test JVM (JAVA_TEST_HOME) is resolvable. | ||
| allArgs.addAll(carrierExportJvmArgs(project)) | ||
| if (extension.nativeLibDir.isPresent) { | ||
| allArgs.add("-Djava.library.path=${extension.nativeLibDir.get().asFile.absolutePath}") | ||
| } | ||
| allArgs.addAll(testConfig.extraJvmArgs) | ||
| allArgs.addAll(testConfig.configJvmArgs) | ||
|
|
||
| // System properties | ||
| testConfig.systemProperties.forEach { (key, value) -> | ||
| allArgs.add("-D$key=$value") | ||
| } | ||
|
|
||
| // Test filter from -Ptests property | ||
| val testsFilter = project.findProperty("tests") as String? | ||
| if (testsFilter != null) { | ||
| allArgs.add("-Dtest.filter=$testsFilter") | ||
| } | ||
|
|
||
| // Profiler options from -Pprofiler.options property | ||
| val profilerOptions = project.findProperty("profiler.options") as String? | ||
| if (profilerOptions != null) { | ||
| allArgs.add("-Dddprof.test.options=$profilerOptions") | ||
| } | ||
|
|
||
| // Classpath | ||
| allArgs.add("-cp") | ||
| allArgs.add(testConfig.testClasspath.asPath) | ||
|
|
||
| // Use custom test runner | ||
| allArgs.add("com.datadoghq.profiler.test.ProfilerTestRunner") | ||
|
|
||
| execTask.args = allArgs | ||
| } | ||
|
|
||
| // Environment variables | ||
| testConfig.environmentVariables.forEach { (key, value) -> | ||
| execTask.environment(key, value) | ||
| } | ||
|
|
||
| // Remove LD_LIBRARY_PATH to let RPATH work correctly | ||
| execTask.doFirst { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it's cleaner do not add LD_LIBRARY_PATH in the loop just above?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you check if it is still the case? I cannot find any loops. |
||
| val currentLdLibPath = (execTask.environment["LD_LIBRARY_PATH"] as? String) ?: System.getenv("LD_LIBRARY_PATH") | ||
| if (!currentLdLibPath.isNullOrEmpty()) { | ||
| project.logger.info("Removing LD_LIBRARY_PATH to prevent cross-JDK library conflicts (was: $currentLdLibPath)") | ||
| execTask.environment.remove("LD_LIBRARY_PATH") | ||
| } | ||
| } | ||
|
|
||
| // Sanitizer conditions | ||
| when (testConfig.configName) { | ||
| "asan" -> { | ||
| execTask.onlyIf { | ||
| PlatformUtils.locateLibasan() != null && | ||
| !PlatformUtils.isTestJvmJ9() | ||
| } | ||
| // Unlike the Test task's asan variant (setForkEvery(25) above), this task | ||
| // is a single un-forked Exec process running the whole suite in one JVM — | ||
| // there is no forkEvery equivalent for Exec. An unfiltered run would | ||
| // reintroduce the late-suite OOM under ASan's -Xmx512m cap that forkEvery | ||
| // was added to avoid, so require -Ptests to bound the run instead. | ||
| execTask.doFirst { | ||
| if (project.findProperty("tests") == null) { | ||
| throw GradleException( | ||
| "$taskName requires -Ptests=<ClassName|ClassName.method> for the " + | ||
| "asan config: it runs in a single process with no forkEvery " + | ||
| "equivalent, and JFR/JMC allocations accumulate under ASan's " + | ||
| "-Xmx512m heap cap until an unfiltered run OOMs late in the suite. " + | ||
| "For full-suite ASan coverage, use the forked testAsan task instead." | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| "tsan" -> execTask.onlyIf { false } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun generateMultiConfigTasks(project: Project, extension: ProfilerTestExtension) { | ||
| val nativeBuildExt = project.rootProject.extensions.findByType(NativeBuildExtension::class.java) | ||
| ?: return // No native build extension, nothing to generate | ||
|
|
@@ -496,6 +606,10 @@ class ProfilerTestPlugin : Plugin<Project> { | |
| createTestTask(project, extension, testConfig, testCfg, sourceSets) | ||
| } | ||
|
|
||
| // Create process-based test task (always uses Exec, available on all platforms) | ||
| // Supports -Pprofiler.options for overriding profiler settings | ||
| createProcessTestTask(project, extension, testConfig, testCfg, sourceSets) | ||
|
|
||
| // Create application tasks for specified configs | ||
| if (configName in applicationConfigs && appMainClass.isNotEmpty()) { | ||
| // Create main configuration | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.