-
Notifications
You must be signed in to change notification settings - Fork 36
Run Emscripten tests in a browser #294
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
base: main
Are you sure you want to change the base?
Run Emscripten tests in a browser #294
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #294 +/- ##
=======================================
Coverage 82.00% 82.00%
=======================================
Files 20 20
Lines 950 950
Branches 87 87
=======================================
Hits 779 779
Misses 171 171 🚀 New features to boost your workflow:
|
32c6236
to
93dd06f
Compare
@@ -69,6 +71,8 @@ if(EMSCRIPTEN) | |||
PUBLIC "SHELL: --preload-file ${SYSROOT_PATH}/include@/include" | |||
PUBLIC "SHELL: --preload-file ../${XEUS_CPP_DATA_DIR}@/share/xeus-cpp" | |||
PUBLIC "SHELL: --preload-file ../${XEUS_CPP_CONF_DIR}@/etc/xeus-cpp" | |||
PUBLIC "SHELL: --emrun" | |||
PUBLIC "SHELL: -s MINIFY_HTML=0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this MINIFY_HTML=0 flag you end up with the situation where the creation of the test_xeus_cpp.html file breaks on MacOS, but not Ubuntu as can be seen here https://github.com/compiler-research/xeus-cpp/actions/runs/14780201517
Running the tests makes use of emrun which comes with Emscripten. The documentation for emrun can be found here https://emscripten.org/docs/compiling/Running-html-files-with-emrun.html |
944d734
to
d72f58a
Compare
micromamba activate xeus-lite-host | ||
cd build/test | ||
os="${{ matrix.os }}" | ||
if [[ "${os}" == "macos"* ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason we install a fresh install of Firefox and Chome is to follow what is done in the Emscripten repo (for example here with Firefox https://github.com/emscripten-core/emscripten/blob/38e16464cffc8f886364fe4919a712131a4c9456/.circleci/config.yml#L363 ). It has the added advantage by not using the users installed versions of these browsers (if they have them installed), that there are no add ons, etc that could be causing issues with the tests running. I have made the instructions, such that a developer without admin privileges on there machine can install them.
|
||
# Run tests in browsers | ||
echo "Running test_xeus_cpp in Firefox" | ||
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" test_xeus_cpp.html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given emrun is not on our PATH, I have to reference the exact path to emrun.py . I could add ${{ env.BUILD_PREFIX }}/bin/
to PATH, but not sure if this would be wanted.
--kill_exit
makes it so that when emrun finishes, that the headless browser we create is killed along with it
--timeout 60
is such that emrun is killed after 60 seconds if still running. emrun should have finished long before then, so if it is still running, something went wrong (such as a test which crashed the html file). This will cause the ci to fail, as a non 0 value of will be returned.
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" test_xeus_cpp.html | ||
echo "Running test_xeus_cpp in Google Chrome" | ||
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" test_xeus_cpp.html | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case of Chrome we have the extra --no-sandbox
flag, as on Ubuntu Chrome will refuse to run otherwise, as it expects to have been installed with admin privileges. This flag allows it to run in userspace.
@@ -69,6 +71,8 @@ if(EMSCRIPTEN) | |||
PUBLIC "SHELL: --preload-file ${SYSROOT_PATH}/include@/include" | |||
PUBLIC "SHELL: --preload-file ../${XEUS_CPP_DATA_DIR}@/share/xeus-cpp" | |||
PUBLIC "SHELL: --preload-file ../${XEUS_CPP_CONF_DIR}@/etc/xeus-cpp" | |||
PUBLIC "SHELL: --emrun" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebuild your Emscripten application and add the --emrun [linker flag](https://emscripten.org/docs/tools_reference/emcc.html#emcc-emrun).
This flag injects code into the generated [Module object](https://emscripten.org/docs/api_reference/module.html#module) to enable capture of stdout, stderr and exit().
Note
If you skip this step, you can still run any .html file with emrun, but the capture will not work.
The above is taken from emruns documentation https://emscripten.org/docs/compiling/Running-html-files-with-emrun.html
|
||
set_target_properties(test_xeus_cpp PROPERTIES | ||
SUFFIX ".html" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that we create a html file, as well as the javascript file.
Description
Please include a summary of changes, motivation and context for this PR.
This PR adds the ability to run the Emscripten tests in a browser
Fixes # (issue)
Type of change
Please tick all options which are relevant.