Repository navigation
test(cuda-oxide): write fake tools through cp - #1579
Open
praveenperera wants to merge 1 commit into
Open
praveenperera wants to merge 1 commit into
praveenperera wants to merge 1 commit into
Conversation
Tests that write a stand-in tool and run it at once could fail with ETXTBSY. While the test holds the script open for writing, another test thread can spawn a process, and that child inherits the handle until it execs. The kernel will not execute a file that has a writer. Renaming a staging file does not help: the inherited handle refers to the same file. Have a cp child create each tool from a staging file instead, so the only process that opens the tool for writing has exited before the test runs it. Signed-off-by: Praveen Perera <[email protected]>
praveenperera
marked this pull request as ready for review
October 20, 2026 20:54
praveenperera
marked this pull request as draft
October 20, 2026 20:55
praveenperera
marked this pull request as ready for review
October 20, 2026 20:56
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The problem
Several unit tests write a small shell script as a stand-in for a tool (llc, opt, clang, tileiras, ptxas) and run it right away. Under parallel test threads they sometimes fail with
Text file busy (os error 26).just checkhit this twice in a row for me, once inptx::tests::debug_builds_fail_when_opt_drops_the_debug_graphand once intileiras_capability_follows_the_listed_bytecode_versions. Both passed on a rerun.The test process holds the script open for writing while
fs::writeruns. If another test thread spawns a process in that window, the child inherits a copy of that file handle.O_CLOEXEConly closes it when the child execs, and until then the kernel refuses to execute a file that has a writer. Writing a staging file and renaming it, aswrite_debug_dropping_toolalready does, does not help: the inherited handle refers to the same file, whatever its name.The fix
The test writes the script to a staging file, and a
cpchild creates the tool from it. The only process that ever opens the tool for writing iscp, and the helper waits for it to exit before returning. Then it sets the mode on the tool, becausecpapplies the umask, and achmodopens no handle.cuda-oxide-codegen/src/ptx.rs: new test helperwrite_tool.write_debug_dropping_tooland the llc stand-in inlegacy_tool_warnings_survive_a_later_llc_failurenow use it, replacing the staging-and-rename version.cargo-oxide/src/commands/tests.rs: the same helper, used bydoctor_clang_fixtureand the tileiras stand-ins.cuda-intrinsics-gen/src/probe.rs:write_fake_toolcreates the tool the same way.ptx-schedule/src/campaign.rs:run_binary_drains_output_larger_than_a_pipe_buffercreatesspam.shthe same way.The helper is copied rather than shared because there is no common test-support crate for these four.
I left out three other tests that write and then execute a script. In
cuda-oxide-codegen/tests/concurrent_compile.rs, the binary has a single test, which writes its tool before starting any threads.cuda-oxide-codegen/tests/compile_to_ptx.rsalready retries until its tool starts.cuda-artifact-finalizeralready retriesETXTBSYwhen it runs the tool.Testing
All runs were on a 24-core machine with Ubuntu 26.04, Linux 7.0 and GNU coreutils 9.7.
Standalone repro: 16 threads each wrote and executed 2,000 scripts, while 8 more threads spawned
truein a loop. That is 32,000 executions per method:ETXTBSYfs::write+chmod(most tests before this change)rename(write_debug_dropping_toolbefore this change)cp(this change)On one failure, the repro scanned
/procand caught the writer: the repro's own forked child, not yet exec'd, holding the script openO_WRONLY|O_CLOEXEC.The four test binaries: I ran each binary directly in 4 parallel copies with every core busy. Each failure listed below is a test whose fake tool could not run.
maincuda-oxide-codegenlibdebug_builds_fail_when_opt_drops_the_debug_graph)cargo-oxidebindoctor_clang_resource_prefers_the_first_successful_candidate)cuda-intrinsics-genbinfake_non_nvidia_ptxas_banner_is_rejected)ptx-schedulelibThe
cargo-oxideruns skip three tests that drivecargoand need the environment thatcargo testprovides; the doctor test there falls through to its second fake clang when the first cannot run. At idle, 40 sequentialcargo testruns per binary did not fail onmain.just checkpasses.