Skip to content
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

fix: make cargo test testnet work on windows #5937

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

fdefelici
Copy link

Description

this patch makes cargo test testnet command work properly on windows.
Addressed:

  • compilation issue due to usage of unix apis
  • test runtime failure due to path naming not supported by windows

Applicable issues

Additional info (benefits, drawbacks, caveats)

Checklist

  • Test coverage for new or modified code paths
  • Changelog is updated
  • Required documentation changes (e.g., docs/rpc/openapi.yaml and rpc-endpoints.md for v2 endpoints, event-dispatcher.md for new events)
  • New clarity functions have corresponding PR in clarity-benchmarking repo
  • New integration test(s) added to bitcoin-tests.yml

@fdefelici fdefelici requested a review from a team as a code owner March 18, 2025 13:57
@fdefelici fdefelici self-assigned this Mar 18, 2025
@aldur aldur requested review from moodmosaic and rdeioris March 19, 2025 15:45
@moodmosaic
Copy link
Member

What do I have to setup/install in order to try?

@fdefelici
Copy link
Author

What do I have to setup/install in order to try?

If you mean locally on your machine:

Prerequisites

  • A windows os (even virtualized)
  • Cloning the PR Repo making sure you set before the git property core.autoclrf = input (as indicated in our readme)

Validation:

  • Run cargo test testnet and the process should end without compilation error and the all tests run succesfully

@moodmosaic
Copy link
Member

Thanks! I can't reproduce this on windows 11 arm64:

rust:
- installed via rustup
- target: aarch64-pc-windows-msvc

visual studio:
- desktop development with c++
- msvc v143 - arm64 build tools
- windows 11 sdk
- c++ arm64 build tools
- clang compiler for arm64
- llvm support

tools confirmed:
- cl.exe
- link.exe
- vcvarsall.bat

@fdefelici, if your setup differs, let me know how to try it on a clean box. I can reset easily.

@wileyj
Copy link
Collaborator

wileyj commented Mar 22, 2025

i was able to get a VM with windows running on x64 to test this - but ran into a strange error that i can't reproduce on other systems.
the sha256 of the stx-genesis files doesn't match (and compile panics due to this). i'll have to verify the files in your fork @fdefelici , or it may be something with the version of sha256 on the windows VM

edit: it definitely seems to be a problem with the tool on windows. linux reports the sha256 of your branch correctly. i'll dig into it a bit more, see if i did something wrong here.

@fdefelici
Copy link
Author

fdefelici commented Mar 22, 2025

i was able to get a VM with windows running on x64 to test this - but ran into a strange error that i can't reproduce on other systems. the sha256 of the stx-genesis files doesn't match (and compile panics due to this). i'll have to verify the files in your fork @fdefelici , or it may be something with the version of sha256 on the windows VM

edit: it definitely seems to be a problem with the tool on windows. linux reports the sha256 of your branch correctly. i'll dig into it a bit more, see if i did something wrong here.

It is the "correct" behaviour by now.
Did you set git property core.autoclrf = input as I mentioned to nikos? Eventually be aware of doing it before you clone the repository.
(I'm also working to fix the need for this configuration and I could submit a PR soon, driven by this issue #4613. As you can see in there it is the same problem you are esperiencing and I provided the same guideline to the user who report it).
So at the moment following our "official" readme, does the trick.

Anyhow considering that the problem is due to file end-of-line, another possibility is just edit the eol from CLRF to LF for the following files:

  • stx-genesis/chainstate.txt
  • stx-genesis/chainstate-test.txt
  • stx-genesis/name_zonefiles-test.txt
  • stx-genesis/name_zonefiles.txt

@fdefelici
Copy link
Author

Thanks! I can't reproduce this on windows 11 arm64:

rust:
- installed via rustup
- target: aarch64-pc-windows-msvc

visual studio:
- desktop development with c++
- msvc v143 - arm64 build tools
- windows 11 sdk
- c++ arm64 build tools
- clang compiler for arm64
- llvm support

tools confirmed:
- cl.exe
- link.exe
- vcvarsall.bat

@fdefelici, if your setup differs, let me know how to try it on a clean box. I can reset easily.

The only difference I have is the target architecture. I have x86_64-pc-windows-msvc
What error do you get?

@moodmosaic
Copy link
Member

@fdefelici
Copy link
Author

@fdefelici, for the build output see: https://gist.github.com/moodmosaic/4a9022de3bd5ef8aa1ab6b3e0ac15a3c

Ok thanks. the problem is clear. It Is due the winapi crate that has not support for arm64.

As far that crate is obsolete we could think to migrate to the windows crate that should have better support for arm64. Anyhow Better to split in a specific issue/pr.

So, by now another prerequisite is that the architetture that must be x86 family

Basically the configuration that @wileyj is testing.

@wileyj
Copy link
Collaborator

wileyj commented Mar 22, 2025

i was able to get a VM with windows running on x64 to test this - but ran into a strange error that i can't reproduce on other systems. the sha256 of the stx-genesis files doesn't match (and compile panics due to this). i'll have to verify the files in your fork @fdefelici , or it may be something with the version of sha256 on the windows VM
edit: it definitely seems to be a problem with the tool on windows. linux reports the sha256 of your branch correctly. i'll dig into it a bit more, see if i did something wrong here.

It is the "correct" behaviour by now. Did you set git property core.autoclrf = input as I mentioned to nikos? Eventually be aware of doing it before you clone the repository. (I'm also working to fix the need for this configuration and I could submit a PR soon, driven by this issue #4613. As you can see in there it is the same problem you are esperiencing and I provided the same guideline to the user who report it). So at the moment following our "official" readme, does the trick.

Anyhow considering that the problem is due to file end-of-line, another possibility is just edit the eol from CLRF to LF for the following files:

  • stx-genesis/chainstate.txt
  • stx-genesis/chainstate-test.txt
  • stx-genesis/name_zonefiles-test.txt
  • stx-genesis/name_zonefiles.txt

confirmed - it was user error. i set the config value as autoclrf. retrying

@wileyj
Copy link
Collaborator

wileyj commented Mar 23, 2025

after fixing the gitconfig, the tests on this branch all pass.
very basic setup on my end: windows 11 evaluation VM, installed git and rustup (which installed missing dependencies).
git clone the fork/branch, cargo test testnet returns 0

@fdefelici
Copy link
Author

@fdefelici, for the build output see: https://gist.github.com/moodmosaic/4a9022de3bd5ef8aa1ab6b3e0ac15a3c

Ok thanks. the problem is clear. It Is due the winapi crate that has not support for arm64.

As far that crate is obsolete we could think to migrate to the windows crate that should have better support for arm64. Anyhow Better to split in a specific issue/pr.

So, by now another prerequisite is that the architetture that must be x86 family

Basically the configuration that @wileyj is testing.

Tracked this issue here #5947

@fdefelici fdefelici mentioned this pull request Mar 23, 2025
5 tasks
@rdeioris
Copy link
Contributor

Tested successfully on an x64 system. I will try with an arm64 asap.

@moodmosaic
Copy link
Member

OK, I got this to work on arm64 — specifically on a clean Windows 11 arm64 VM. This time I used only PortableGit and Skeeto's w64devkit. No MSVC, no Visual Studio, no Windows SDKs, no system-wide installs.


Notes:

  1. rustup-init with aarch64-pc-windows-gnu failed (unsupported?)
    Used x86_64-pc-windows-gnu under emulation instead:

    ./rustup-init.exe --default-host x86_64-pc-windows-gnu
  2. Added w64devkit to PATH (otherwise cargo can't find gcc).

  3. Build failed with:

    ld.exe: cannot find -lgcc_eh
    

    Rust's GNU toolchain expects libgcc_eh.a, but w64devkit doesn’t include it (by design, it uses compiler-rt).

  4. Fixed by creating a dummy static archive:

    cd w64devkit/x86_64-w64-mingw32/lib
    ar rcs libgcc_eh.a

    This keeps the linker happy. Confirmed here:
    Error while using mingw as a linker for rust skeeto/w64devkit#52

  5. Re-ran:

    cargo test testnet

Copy link
Member

@moodmosaic moodmosaic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on Windows ARM64 with w64devkit. Left a small nit.

echo ]
)
"#;
let path = "/tmp/test-get-unconfirmed-commits.bat";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works in Git Bash but might not work in PowerShell, perhaps a more portable way could be

Suggested change
let path = "/tmp/test-get-unconfirmed-commits.bat";
let path = std::env::temp_dir().join("test-get-unconfirmed-commits.bat");

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this should be the right way. I was aware of that but didn't fix it here, because in all our codebase all tests doing filesystem I/O use /tmp as root folder (and if the folder doesn't exists it is automatically created).

Infact if you run cargo test testnet from both cmd or powershell the tests should ends succesfully.

For sure this need to be improved, but I would prefer doing it in more general fashion in this issue #5932.
So, if you agree, we can leave it as it is (to keep the tests homogeneous for now), and face it in the dedicated issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... AFAICT, the test runs the script, parses JSON output, and checks values. But the batch file won't run directly in PowerShell (unless they are prefixed with e.g. .\script.bat?).

Perhaps the safest is to invoke it explicitly via cmd.exe, e.g.:

let output = Command::new("cmd")
    .args(["/C", path])
    .output()
    .expect("Failed to execute batch script");

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure and clear my understanding: did you tried running from powershell and you got some error?

I'm just asking for confirmation, because I tried to run from powershell these commands with success:

  • cargo run testnet
  • C:\tmp\test-get-unconfirmed-commits.bat
  • /tmp/test-get-unconfirmed-commits.bat

The only way I'm able to get an error (the one you describe) is when running the bat file with relative path.
So doing this gives error:

cd tmp
test-get-unconfirmed-commits.bat

//I got some red error and then this hint
Suggestion [3,General]: The command test-get-unconfirmed-commits.bat was not found, but it exists in the current path. By default, Windows PowerShell does not load commands from the current path. If you trust the command, type ".\test-get-unconfirmed-commits.bat" instead. For more information, see "get-help about_Command_Precedence".

So by the fact we run it in the test with absolute path, we shouldn't have any error.

Instead if you got error, please share it, so I can collect it for later analysis (hopefully even the powershell version), and eventually I can apply the patch your proposing.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

running cargo test testnet worked both on cmd and powershell on my end

@aldur aldur requested a review from wileyj March 24, 2025 15:39
Copy link
Contributor

@rdeioris rdeioris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (tested on x64 windows 11)

Copy link

@Jiloc Jiloc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on Win11 x64, works great. Just left a comment for a documentation nit

obycode
obycode previously approved these changes Mar 26, 2025
Copy link
Contributor

@obycode obycode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks fine to me 👍

@fdefelici fdefelici requested a review from moodmosaic March 27, 2025 08:23
Copy link

codecov bot commented Mar 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.51%. Comparing base (51169a6) to head (bbd5236).
Report is 98 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #5937      +/-   ##
===========================================
+ Coverage    82.88%   84.51%   +1.63%     
===========================================
  Files          522      522              
  Lines       382715   381322    -1393     
  Branches       323      323              
===========================================
+ Hits        317232   322293    +5061     
+ Misses       65475    59021    -6454     
  Partials         8        8              
Files with missing lines Coverage Δ
stackslib/src/config/chain_data.rs 75.11% <ø> (ø)
stackslib/src/net/mod.rs 78.68% <100.00%> (-0.02%) ⬇️
stackslib/src/net/tests/convergence.rs 93.77% <ø> (+11.49%) ⬆️

... and 104 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e21c0dd...bbd5236. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@moodmosaic moodmosaic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely improves support for Windows, working even on the bare-bones setup, as pointed out in #5937 (comment). Looks good to me.

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.

6 participants