Skip to content

Commit e295736

Browse files
committed
Run Emscripten tests in a browser
1 parent 97daaeb commit e295736

File tree

6 files changed

+300
-13
lines changed

6 files changed

+300
-13
lines changed

.github/workflows/deploy-github-page.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
pushd build
5252
5353
export BUILD_PREFIX=$MAMBA_ROOT_PREFIX/envs/xeus-cpp-wasm-build
54+
echo "BUILD_PREFIX=$BUILD_PREFIX" >> $GITHUB_ENV
5455
export PREFIX=$MAMBA_ROOT_PREFIX/envs/xeus-cpp-wasm-host
5556
echo "PREFIX=$PREFIX" >> $GITHUB_ENV
5657
export SYSROOT_PATH=$BUILD_PREFIX/opt/emsdk/upstream/emscripten/cache/sysroot
@@ -65,6 +66,77 @@ jobs:
6566
..
6667
emmake make -j ${{ env.ncpus }} install
6768
69+
- name: Test xeus-cpp C++ Emscripten
70+
shell: bash -l {0}
71+
run: |
72+
set -e
73+
micromamba create -n xeus-lite-host jupyterlite-core
74+
micromamba activate xeus-lite-host
75+
cd build/test
76+
# Fresh install browsers, and run Emscripten tests in them
77+
# This is to match the Emscripten build instructions, where
78+
# we run in a fresh browser, to stop any extra installed
79+
# stuff interferring with the running of the tests
80+
# Explaination of options for emrun
81+
# --browser (name of browser on path)
82+
# --kill_exit makes it so that when emrun finishes,
83+
# that the headless browser we create is killed along with it
84+
# --timeout 60 is such that emrun is killed after 60 seconds if
85+
# still running. emrun should have finished long before then,
86+
# so if it is still running, something went wrong (such as a test
87+
# which crashed the html file). This will cause the ci to fail,
88+
# as a non 0 value of will be returned.
89+
# In the case of Chrome we have the extra --no-sandbox flag, as on
90+
# Ubuntu Chrome will refuse to run otherwise, as it expects to have
91+
# been installed with admin privileges. This flag allows it to run
92+
# in userspace.
93+
os="${{ matrix.os }}"
94+
if [[ "${os}" == "macos"* ]]; then
95+
# Install Firefox
96+
wget "https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US" -O Firefox-latest.dmg
97+
hdiutil attach Firefox-latest.dmg
98+
cp -r /Volumes/Firefox/Firefox.app $PWD
99+
hdiutil detach /Volumes/Firefox
100+
cd ./Firefox.app/Contents/MacOS/
101+
export PATH="$PWD:$PATH"
102+
cd –
103+
104+
# Install Google Chrome
105+
wget https://dl.google.com/chrome/mac/stable/accept_tos%3Dhttps%253A%252F%252Fwww.google.com%252Fintl%252Fen_ph%252Fchrome%252Fterms%252F%26_and_accept_tos%3Dhttps%253A%252F%252Fpolicies.google.com%252Fterms/googlechrome.pkg
106+
pkgutil --expand-full googlechrome.pkg google-chrome
107+
cd ./google-chrome/GoogleChrome.pkg/Payload/Google\ Chrome.app/Contents/MacOS/
108+
export PATH="$PWD:$PATH"
109+
cd –
110+
111+
# Run tests in browsers
112+
echo "Running test_xeus_cpp in Firefox"
113+
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --browser="firefox" --kill_exit --browser-args="--headless" test_xeus_cpp.html
114+
echo "Running test_xeus_cpp in Google Chrome"
115+
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --browser="Google Chrome" --kill_exit --browser-args="--headless" test_xeus_cpp.html
116+
else
117+
# Install Google Chrome
118+
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
119+
dpkg-deb -x google-chrome-stable_current_amd64.deb $PWD/chrome
120+
cd ./chrome/opt/google/chrome/
121+
export PATH="$PWD:$PATH"
122+
cd -
123+
124+
# Install Firefox
125+
wget https://ftp.mozilla.org/pub/firefox/releases/138.0.1/linux-x86_64/en-GB/firefox-138.0.1.tar.xz
126+
tar -xJf firefox-138.0.1.tar.xz
127+
cd ./firefox
128+
export PATH="$PWD:$PATH"
129+
cd -
130+
131+
# Run tests in browsers
132+
echo "Running test_xeus_cpp in Firefox"
133+
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" test_xeus_cpp.html
134+
echo "Running test_xeus_cpp in Google Chrome"
135+
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" test_xeus_cpp.html
136+
fi
137+
node test_xeus_cpp.js
138+
timeout-minutes: 4
139+
68140
- name: Jupyter Lite integration
69141
shell: bash -l {0}
70142
run: |

.github/workflows/main.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ jobs:
234234
pushd build
235235
236236
export BUILD_PREFIX=$MAMBA_ROOT_PREFIX/envs/xeus-cpp-wasm-build
237+
echo "BUILD_PREFIX=$BUILD_PREFIX" >> $GITHUB_ENV
237238
export PREFIX=$MAMBA_ROOT_PREFIX/envs/xeus-cpp-wasm-host
238239
echo "PREFIX=$PREFIX" >> $GITHUB_ENV
239240
export SYSROOT_PATH=$BUILD_PREFIX/opt/emsdk/upstream/emscripten/cache/sysroot
@@ -251,10 +252,72 @@ jobs:
251252
- name: Test xeus-cpp C++ Emscripten
252253
shell: bash -l {0}
253254
run: |
255+
export BUILD_PREFIX=$MAMBA_ROOT_PREFIX/envs/xeus-cpp-wasm-build
254256
set -e
255257
micromamba create -n xeus-lite-host jupyterlite-core
256258
micromamba activate xeus-lite-host
257259
cd build/test
260+
# Fresh install browsers, and run Emscripten tests in them
261+
# This is to match the Emscripten build instructions, where
262+
# we run in a fresh browser, to stop any extra installed
263+
# stuff interferring with the running of the tests
264+
# Explaination of options for emrun
265+
# --browser (name of browser on path)
266+
# --kill_exit makes it so that when emrun finishes,
267+
# that the headless browser we create is killed along with it
268+
# --timeout 60 is such that emrun is killed after 60 seconds if
269+
# still running. emrun should have finished long before then,
270+
# so if it is still running, something went wrong (such as a test
271+
# which crashed the html file). This will cause the ci to fail,
272+
# as a non 0 value of will be returned.
273+
# In the case of Chrome we have the extra --no-sandbox flag, as on
274+
# Ubuntu Chrome will refuse to run otherwise, as it expects to have
275+
# been installed with admin privileges. This flag allows it to run
276+
# in userspace.
277+
os="${{ matrix.os }}"
278+
if [[ "${os}" == "macos"* ]]; then
279+
# Install Firefox
280+
wget "https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US" -O Firefox-latest.dmg
281+
hdiutil attach Firefox-latest.dmg
282+
cp -r /Volumes/Firefox/Firefox.app $PWD
283+
hdiutil detach /Volumes/Firefox
284+
cd ./Firefox.app/Contents/MacOS/
285+
export PATH="$PWD:$PATH"
286+
cd -
287+
288+
# Install Google Chrome
289+
wget https://dl.google.com/chrome/mac/stable/accept_tos%3Dhttps%253A%252F%252Fwww.google.com%252Fintl%252Fen_ph%252Fchrome%252Fterms%252F%26_and_accept_tos%3Dhttps%253A%252F%252Fpolicies.google.com%252Fterms/googlechrome.pkg
290+
pkgutil --expand-full googlechrome.pkg google-chrome
291+
cd ./google-chrome/GoogleChrome.pkg/Payload/Google\ Chrome.app/Contents/MacOS/
292+
export PATH="$PWD:$PATH"
293+
cd -
294+
295+
# Run tests in browsers
296+
echo "Running test_xeus_cpp in Firefox"
297+
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" test_xeus_cpp.html
298+
echo "Running test_xeus_cpp in Google Chrome"
299+
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --browser="Google Chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" test_xeus_cpp.html
300+
else
301+
# Install Google Chrome
302+
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
303+
dpkg-deb -x google-chrome-stable_current_amd64.deb $PWD/chrome
304+
cd ./chrome/opt/google/chrome/
305+
export PATH="$PWD:$PATH"
306+
cd -
307+
308+
# Install Firefox
309+
wget https://ftp.mozilla.org/pub/firefox/releases/138.0.1/linux-x86_64/en-GB/firefox-138.0.1.tar.xz
310+
tar -xJf firefox-138.0.1.tar.xz
311+
cd ./firefox
312+
export PATH="$PWD:$PATH"
313+
cd -
314+
315+
# Run tests in browsers
316+
echo "Running test_xeus_cpp in Firefox"
317+
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" test_xeus_cpp.html
318+
echo "Running test_xeus_cpp in Google Chrome"
319+
python ${{ env.BUILD_PREFIX }}/bin/emrun.py --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" test_xeus_cpp.html
320+
fi
258321
node test_xeus_cpp.js
259322
timeout-minutes: 4
260323

CONTRIBUTING.md

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,57 @@ emcmake cmake \
9494
emmake make install
9595
```
9696

97+
To test the lite build you can execute the following to run the C++ tests built against emscripten in node
98+
99+
```bash
100+
cd test
101+
node test_xeus_cpp.js
102+
```
103+
104+
It is possible to run the Emscripten tests in a headless browser. We will run our tests in a fresh installed browser. Installing the browsers, and running the tests within the installed browsers will be platform dependent. To do this on MacOS execute the following
105+
106+
```bash
107+
wget "https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US" -O Firefox-latest.dmg
108+
hdiutil attach Firefox-latest.dmg
109+
cp -r /Volumes/Firefox/Firefox.app $PWD
110+
hdiutil detach /Volumes/Firefox
111+
cd ./Firefox.app/Contents/MacOS/
112+
export PATH="$PWD:$PATH"
113+
cd
114+
115+
wget https://dl.google.com/chrome/mac/stable/accept_tos%3Dhttps%253A%252F%252Fwww.google.com%252Fintl%252Fen_ph%252Fchrome%252Fterms%252F%26_and_accept_tos%3Dhttps%253A%252F%252Fpolicies.google.com%252Fterms/googlechrome.pkg
116+
pkgutil --expand-full googlechrome.pkg google-chrome
117+
cd ./google-chrome/GoogleChrome.pkg/Payload/Google\ Chrome.app/Contents/MacOS/
118+
export PATH="$PWD:$PATH"
119+
cd
120+
121+
echo "Running test_xeus_cpp in Firefox"
122+
python $BUILD_PREFIX/bin/emrun.py --browser="firefox" --kill_exit --browser-args="--headless" test_xeus_cpp.html
123+
echo "Running test_xeus_cpp in Google Chrome"
124+
python $BUILD_PREFIX/bin/emrun.py --browser="Google Chrome" --kill_exit --browser-args="--headless --no-sandbox" test_xeus_cpp.html
125+
```
126+
127+
To do this on Ubuntu x86 execute the following
128+
129+
```bash
130+
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
131+
dpkg-deb -x google-chrome-stable_current_amd64.deb $PWD/chrome
132+
cd ./chrome/opt/google/chrome/
133+
export PATH="$PWD:$PATH"
134+
cd -
135+
136+
wget https://ftp.mozilla.org/pub/firefox/releases/138.0.1/linux-x86_64/en-GB/firefox-138.0.1.tar.xz
137+
tar -xJf firefox-138.0.1.tar.xz
138+
cd ./firefox
139+
export PATH="$PWD:$PATH"
140+
cd -
141+
142+
echo "Running test_xeus_cpp in Firefox"
143+
python $BUILD_PREFIX/bin/emrun.py --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" test_xeus_cpp.html
144+
echo "Running test_xeus_cpp in Google Chrome"
145+
python $BUILD_PREFIX/bin/emrun.py --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" test_xeus_cpp.html
146+
```
147+
97148
To build Jupyter Lite with this kernel without creating a website you can execute the following
98149
```bash
99150
micromamba create -n xeus-lite-host jupyterlite-core -c conda-forge
@@ -106,9 +157,3 @@ Once the Jupyter Lite site has built you can test the website locally by executi
106157
```bash
107158
jupyter lite serve --XeusAddon.prefix=$PREFIX
108159
```
109-
110-
To test the lite build you can execute the following to run the C++ tests built against emscripten
111-
```bash
112-
cd test
113-
node test_xeus_cpp.js
114-
```

README.md

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,57 @@ emcmake cmake \
9595
emmake make install
9696
```
9797

98+
To test the lite build you can execute the following to run the C++ tests built against emscripten in node
99+
100+
```bash
101+
cd test
102+
node test_xeus_cpp.js
103+
```
104+
105+
It is possible to run the Emscripten tests in a headless browser. We will run our tests in a fresh installed browser. Installing the browsers, and running the tests within the installed browsers will be platform dependent. To do this on MacOS execute the following
106+
107+
```bash
108+
wget "https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US" -O Firefox-latest.dmg
109+
hdiutil attach Firefox-latest.dmg
110+
cp -r /Volumes/Firefox/Firefox.app $PWD
111+
hdiutil detach /Volumes/Firefox
112+
cd ./Firefox.app/Contents/MacOS/
113+
export PATH="$PWD:$PATH"
114+
cd -
115+
116+
wget https://dl.google.com/chrome/mac/stable/accept_tos%3Dhttps%253A%252F%252Fwww.google.com%252Fintl%252Fen_ph%252Fchrome%252Fterms%252F%26_and_accept_tos%3Dhttps%253A%252F%252Fpolicies.google.com%252Fterms/googlechrome.pkg
117+
pkgutil --expand-full googlechrome.pkg google-chrome
118+
cd ./google-chrome/GoogleChrome.pkg/Payload/Google\ Chrome.app/Contents/MacOS/
119+
export PATH="$PWD:$PATH"
120+
cd -
121+
122+
echo "Running test_xeus_cpp in Firefox"
123+
python $BUILD_PREFIX/bin/emrun.py --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" test_xeus_cpp.html
124+
echo "Running test_xeus_cpp in Google Chrome"
125+
python python $BUILD_PREFIX/bin/emrun.py --browser="Google Chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" test_xeus_cpp.html
126+
```
127+
128+
To do this on Ubuntu x86 execute the following
129+
130+
```bash
131+
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
132+
dpkg-deb -x google-chrome-stable_current_amd64.deb $PWD/chrome
133+
cd ./chrome/opt/google/chrome/
134+
export PATH="$PWD:$PATH"
135+
cd -
136+
137+
wget https://ftp.mozilla.org/pub/firefox/releases/138.0.1/linux-x86_64/en-GB/firefox-138.0.1.tar.xz
138+
tar -xJf firefox-138.0.1.tar.xz
139+
cd ./firefox
140+
export PATH="$PWD:$PATH"
141+
cd -
142+
143+
echo "Running test_xeus_cpp in Firefox"
144+
python $BUILD_PREFIX/bin/emrun.py --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" test_xeus_cpp.html
145+
echo "Running test_xeus_cpp in Google Chrome"
146+
python $BUILD_PREFIX/bin/emrun.py --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" test_xeus_cpp.html
147+
```
148+
98149
To build Jupyter Lite with this kernel without creating a website you can execute the following
99150
```bash
100151
micromamba create -n xeus-lite-host jupyterlite-core -c conda-forge
@@ -108,12 +159,6 @@ Once the Jupyter Lite site has built you can test the website locally by executi
108159
jupyter lite serve --XeusAddon.prefix=$PREFIX
109160
```
110161

111-
To test the lite build you can execute the following to run the C++ tests built against emscripten
112-
```bash
113-
cd test
114-
node test_xeus_cpp.js
115-
```
116-
117162
## Trying it online
118163

119164
To try out xeus-cpp interactively in your web browser, just click on the binder link:

docs/source/InstallationAndUsage.rst

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,57 @@ You are now in a position to build the xeus-cpp kernel. You build it by executin
8282
emmake make install
8383
8484
85+
To test the lite build you can execute the following to run the C++ tests built against emscripten in node
86+
87+
.. code-block:: bash
88+
89+
cd test
90+
node test_xeus_cpp.js
91+
92+
It is possible to run the Emscripten tests in a headless browser. We will run our tests in a fresh installed browser. Installing the browsers, and running the tests within the installed browsers will be platform dependent. To do this on MacOS execute the following
93+
94+
.. code-block:: bash
95+
96+
wget "https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US" -O Firefox-latest.dmg
97+
hdiutil attach Firefox-latest.dmg
98+
cp -r /Volumes/Firefox/Firefox.app $PWD
99+
hdiutil detach /Volumes/Firefox
100+
cd ./Firefox.app/Contents/MacOS/
101+
export PATH="$PWD:$PATH"
102+
cd -
103+
104+
wget https://dl.google.com/chrome/mac/stable/accept_tos%3Dhttps%253A%252F%252Fwww.google.com%252Fintl%252Fen_ph%252Fchrome%252Fterms%252F%26_and_accept_tos%3Dhttps%253A%252F%252Fpolicies.google.com%252Fterms/googlechrome.pkg
105+
pkgutil --expand-full googlechrome.pkg google-chrome
106+
cd ./google-chrome/GoogleChrome.pkg/Payload/Google\ Chrome.app/Contents/MacOS/
107+
export PATH="$PWD:$PATH"
108+
cd -
109+
110+
echo "Running test_xeus_cpp in Firefox"
111+
python $BUILD_PREFIX/bin/emrun.py --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" test_xeus_cpp.html
112+
echo "Running test_xeus_cpp in Google Chrome"
113+
python $BUILD_PREFIX/bin/emrun.py --browser="Google Chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" test_xeus_cpp.html
114+
115+
To do this on Ubuntu x86 execute the following
116+
117+
.. code-block:: bash
118+
119+
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
120+
dpkg-deb -x google-chrome-stable_current_amd64.deb $PWD/chrome
121+
cd ./chrome/opt/google/chrome/
122+
export PATH="$PWD:$PATH"
123+
cd -
124+
125+
wget https://ftp.mozilla.org/pub/firefox/releases/138.0.1/linux-x86_64/en-GB/firefox-138.0.1.tar.xz
126+
tar -xJf firefox-138.0.1.tar.xz
127+
cd ./firefox
128+
export PATH="$PWD:$PATH"
129+
cd -
130+
131+
echo "Running test_xeus_cpp in Firefox"
132+
python $BUILD_PREFIX/bin/emrun.py --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" test_xeus_cpp.html
133+
echo "Running test_xeus_cpp in Google Chrome"
134+
python $BUILD_PREFIX/bin/emrun.py --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" test_xeus_cpp.html
135+
85136
To build Jupyter Lite with this kernel without creating a website you can execute the following
86137

87138
.. code-block:: bash

test/CMakeLists.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,16 @@ if(EMSCRIPTEN)
5656
target_compile_options(test_xeus_cpp
5757
PUBLIC "SHELL: -fexceptions"
5858
)
59-
59+
# So we create a html file, as well as the javascript file
60+
set_target_properties(test_xeus_cpp PROPERTIES
61+
SUFFIX ".html"
62+
)
63+
# --emrun
64+
# Makes it so that we run the html file created by this target, that we can capture the
65+
# standard output and output it to the terminal
66+
# MINIFY_HTML=0
67+
# Without this MINIFY_HTML=0 flag you end up with the situation where the creation of the
68+
# test_xeus_cpp.html file breaks on MacOS, but not Ubuntu
6069
target_link_options(test_xeus_cpp
6170
PUBLIC "SHELL: -fexceptions"
6271
PUBLIC "SHELL: -s MAIN_MODULE=1"
@@ -69,6 +78,8 @@ if(EMSCRIPTEN)
6978
PUBLIC "SHELL: --preload-file ${SYSROOT_PATH}/include@/include"
7079
PUBLIC "SHELL: --preload-file ../${XEUS_CPP_DATA_DIR}@/share/xeus-cpp"
7180
PUBLIC "SHELL: --preload-file ../${XEUS_CPP_CONF_DIR}@/etc/xeus-cpp"
81+
PUBLIC "SHELL: --emrun"
82+
PUBLIC "SHELL: -s MINIFY_HTML=0"
7283
)
7384

7485
target_include_directories(test_xeus_cpp PRIVATE ${XEUS_CPP_INCLUDE_DIR})

0 commit comments

Comments
 (0)