Skip to content

Conversation

@jhpohovey
Copy link

Problem

run_tests.py, when run like in the following snippet, doesn't work on Windows (read: normal Windows, not WSL or a Docker container running in Windows) because of two issues:

cuda-samples/README.md

Lines 331 to 335 in c94ff36

Now, return to the samples root directory and run the test script:
```bash
cd ..
python3 run_tests.py --output ./test --dir ./build/Samples --config test_args.json
```

1. os.access(path, os. X_OK) is ineffective on Windows

On Linux, this checks the executable permission bit and works completely fine. But on Windows, it returns True for most things- including .md files, directories, etc (primarily due to lots of Posix-like things that don't map quite exactly). This causes the script to try running thousands of non-executable files.

The underlying implementation of os.access unfolds to:
https://github.com/python/cpython/blob/fddc24e4c85467f14075e94fd0d23d928ceb535f/Modules/posixmodule.c?plain=1#L3764-L3780
where executability isn't checked (see python/cpython#46780).

2. ./executable syntax doesn't work in subprocess on non-Unix-like machines

The original code used cmd = [f"./{exe_name}"], but Windows (Power Shell and Command Prompt), unlike *nix-based platforms, doesn't understand the ./ syntax in subprocess.run() without shell=True (using shell=True would spawn e.g., a cmd.exe for every single test run, which is likely not preferable if it could be done without). There are also some hypothetical security concerns from injection when shell=True.

Solution

  • Add a simple .exe filter on Windows. Yes there are other file-types in Windows that are executable, like .bat or .cmd, but their inclusion (or lack thereof) is generally irrelevant since the CMake process isn't compiling anything into batch or command scripts.
  • Use the full resolved path instead of ./ prefix. This works everywhere without needing shell interpretation - Windows can execute C:\path\to\program.exe directly, and Linux handles /path/to/program the same way.

Changes

  • find_executables(): Skip non-.exe files on Windows.
  • run_single_test_instance(): Use executable.resolve() instead of f"./{exe_name}".

Testing

  • Pre-commit hooks pass
  • 183/184 test runs completed successfully after building (with simpleP2P, streamOrderedAllocationP2P, conjugateGradientMultiDeviceCG, and simpleCUFFT skipped due to testing on a 1-GPU system). The test of simpleAWBarrier hangs and hits timeout after 5min, both with and without these changes (not that changes to a .py file should impact compilation either way; this is likely a driver+platform specific issue on my end).

Since this change modifies the test runner itself rather than the samples, the tests running+passing validates that the runner correctly discovers and executes the sample executables on Windows. Before this fix, the script would fail immediately trying to execute non-executable files, if it were to discover them at all.

@jhpohovey jhpohovey force-pushed the fix-windows-test-run branch from 373b2e9 to de2ad6a Compare December 2, 2025 19:43
@jhpohovey
Copy link
Author

fixing noisy diff caused by LF vs CRLF difference in above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant