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

test,doc: enable running embedtest for Windows #52646

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

vmoroz
Copy link
Member

@vmoroz vmoroz commented Apr 22, 2024

Currently the embedtest does not run on Windows.
One of the main reasons is that the Windows command line does not accept UTF-8 characters required by the test.

In this PR we enable embedtest to run on Windows:

  • Use node::FixupMain from tools/executable_wrapper.h to fix argc and argv values. The NODE_MAIN macro is defined as wmain for Windows targets that receives parameters as UTF-16. Then, the node::FixupMain converts them to UTF-8.
  • Make sure that we read and write snapshot files as binary files. Windows uses text mode by default.
  • Add calling embedtest to vcbuild.bat as a part of cctest call. It is currently implemented the same way in the Makefile.
  • Makefile is changed to add tools include directory for the embedtest project. It is need to include the executable_wrapper.h.
  • Fix small typo in embedding.md file.

@vmoroz vmoroz requested a review from joyeecheung April 22, 2024 17:29
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/gyp

@nodejs-github-bot nodejs-github-bot added build Issues and PRs related to build files or the CI. needs-ci PRs that need a full CI run. windows Issues and PRs related to the Windows platform. labels Apr 22, 2024
@lpinca lpinca added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 23, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 23, 2024
@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@joyeecheung joyeecheung left a comment

Choose a reason for hiding this comment

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

We already have tools/executable_wrapper.h and AFAICT it serves the same purpose. Not sure why this wasn't done for the embedtest although that wrapper was introduced later when we do need to create executable that also works on Windows (js2c). Can we just use that for the embedtest?

@vmoroz
Copy link
Member Author

vmoroz commented Apr 23, 2024

We already have tools/executable_wrapper.h and AFAICT it serves the same purpose. Not sure why this wasn't done for the embedtest although that wrapper was introduced later when we do need to create executable that also works on Windows (js2c). Can we just use that for the embedtest?

Great! It could work.

For the PR #43542 I will need to make tools/executable_wrapper.h compatible with C.
It was the reason why the new APIs were done to match C calling conventions.
Since tools/executable_wrapper.h is header-only it must be trivial to do as part of PR #43542.

@joyeecheung
Copy link
Member

IIUC to share code with #43542 ultimately we need to expose a helper like node::FixupMain to node.h. That sounds like a good idea, because the UTF8 convention is not currently surfaced to node.h, and we can also use it to remove the repeated code in src/node_main.cc. Not sure about how useful/appropriate it is for the C API, I'll defer that to the n-api team.

@vmoroz
Copy link
Member Author

vmoroz commented Apr 23, 2024

It seems that we can avoid converting the node::FixupMain to C.
#43542 adds two new executables to the embedtest directory.
The simplest approach would be to add testmain.cc that is reused across all three executables.
It will be a C++ file and it will use the node::FixupMain. It then will call TestMain function for each test executable.
Anyway, the change will be implemented in the #43542.
This PR will be greatly simplified by using the node::FixupMain.

As for the src/node_main.cc, I see that it has a copy of tools/executable_wrapper.h code.
I guess we include tools/executable_wrapper.h to src/node_main.ccto reuse it.
I can create a separate PR for it.

@vmoroz vmoroz marked this pull request as draft April 23, 2024 21:12
@vmoroz vmoroz marked this pull request as ready for review April 23, 2024 21:30
@vmoroz
Copy link
Member Author

vmoroz commented Apr 24, 2024

It seems that macOS benchmark is failing, but the failure is not related to changes in this PR.
I guess something else makes the test to break.

@mhdawson
Copy link
Member

I think that is one of the known flaky tests, restarted the github action on macOS

@joyeecheung
Copy link
Member

I guess we include tools/executable_wrapper.h to src/node_main.cc to reuse it.

I think the reason why we don't do that is, we generally try to keep src/node_main.cc rely only on node.h and not any internal headers (I am not sure if that's just my impression at this point, or is that something really enforced). But tackling that in a different PR SGTM.

@joyeecheung joyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 25, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 25, 2024
@nodejs-github-bot
Copy link
Collaborator

@vmoroz vmoroz added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 29, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 29, 2024
@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

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

LGTM

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@vmoroz
Copy link
Member Author

vmoroz commented May 4, 2024

It seem that CI shows that the new embedding testing is failing on Windows and it is related to this PR. I am going to investigate/fix it. I wonder if the child.stderr is changed last week.

10:18:57 > echo running 'Release\node.exe test\embedding\test-embedding.js' 
10:18:57 running 'Release\node.exe test\embedding\test-embedding.js'
10:18:57 
10:18:57 > "Release\node.exe" test\embedding\test-embedding.js 
10:18:57 [process 0]: --- stderr ---
10:18:57 c:\workspace\node-test-binary-windows-native-suites\node\test\common\child_process.js:82
10:18:57     console.error(stderrStr === undefined ? child.stderr.toString() : stderrStr);
10:18:57                                                          ^
10:18:57 
10:18:57 TypeError: Cannot read properties of null (reading 'toString')
10:18:57     at logAndThrow (c:\workspace\node-test-binary-windows-native-suites\node\test\common\child_process.js:82:58)
10:18:57     at expectSyncExit (c:\workspace\node-test-binary-windows-native-suites\node\test\common\child_process.js:91:5)
10:18:57     at spawnSyncAndAssert (c:\workspace\node-test-binary-windows-native-suites\node\test\common\child_process.js:131:10)
10:18:57     at Object.<anonymous> (c:\workspace\node-test-binary-windows-native-suites\node\test\embedding\test-embedding.js:27:1)
10:18:57     at Module._compile (node:internal/modules/cjs/loader:1480:14)
10:18:57     at Module._extensions..js (node:internal/modules/cjs/loader:1564:10)
10:18:57     at Module.load (node:internal/modules/cjs/loader:1287:32)
10:18:57     at Module._load (node:internal/modules/cjs/loader:1103:12)
10:18:57     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:168:12)
10:18:57     at node:internal/main/run_main_module:30:49

@vmoroz vmoroz force-pushed the pr/enable_embedtest_for_windows branch from 51f2daa to 73d5bda Compare May 4, 2024 20:00
@vmoroz vmoroz added the request-ci Add this label to start a Jenkins CI on a PR. label May 5, 2024
@github-actions github-actions bot added request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. and removed request-ci Add this label to start a Jenkins CI on a PR. labels May 5, 2024
Copy link
Contributor

github-actions bot commented May 5, 2024

Failed to start CI
   ⚠  Something was pushed to the Pull Request branch since the last approving review.
   ✘  Refusing to run CI on potentially unsafe PR
https://github.com/nodejs/node/actions/runs/8958495093

@vmoroz
Copy link
Member Author

vmoroz commented May 6, 2024

I had to rebase the PR since the test break on Windows seemed to be caused by PR being submitted against Node.js version 22 while now we have the version 23.

@vmoroz vmoroz requested a review from mhdawson May 6, 2024 22:33
Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

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

LGTM

@mhdawson mhdawson added request-ci Add this label to start a Jenkins CI on a PR. and removed request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. labels May 7, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 7, 2024
@nodejs-github-bot
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Issues and PRs related to build files or the CI. needs-ci PRs that need a full CI run. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants