Skip to content

Commit 4e585a2

Browse files
committed
Run Emscripten tests in a browser
1 parent 28ba16e commit 4e585a2

File tree

6 files changed

+300
-2
lines changed

6 files changed

+300
-2
lines changed

.github/workflows/deploy-pages.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,53 @@ jobs:
145145
../
146146
fi
147147
emmake make -j ${{ env.ncpus }} check-cppinterop
148+
cd ./unittests/CppInterOp/
149+
150+
# Fresh install browsers, and run Emscripten tests in them
151+
# This is to match the Emscripten build instructions, where
152+
# we run in a fresh browser, to stop any extra installed
153+
# stuff interferring with the running of the tests
154+
# Explaination of options for emrun
155+
# --browser (name of browser on path)
156+
# --kill_exit makes it so that when emrun finishes,
157+
# that the headless browser we create is killed along with it
158+
# --timeout 60 is such that emrun is killed after 60 seconds if
159+
# still running. emrun should have finished long before then,
160+
# so if it is still running, something went wrong (such as a test
161+
# which crashed the html file). This will cause the ci to fail,
162+
# as a non 0 value of will be returned.
163+
# In the case of Chrome we have the extra --no-sandbox flag, as on
164+
# Ubuntu Chrome will refuse to run otherwise, as it expects to have
165+
# been installed with admin privileges. This flag allows it to run
166+
# in userspace.
167+
168+
# Install Firefox
169+
wget "https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US" -O Firefox-latest.dmg
170+
hdiutil attach Firefox-latest.dmg
171+
cp -r /Volumes/Firefox/Firefox.app $PWD
172+
hdiutil detach /Volumes/Firefox
173+
cd ./Firefox.app/Contents/MacOS/
174+
export PATH="$PWD:$PATH"
175+
cd -
176+
177+
# Install Google Chrome
178+
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
179+
pkgutil --expand-full googlechrome.pkg google-chrome
180+
cd ./google-chrome/GoogleChrome.pkg/Payload/Google\ Chrome.app/Contents/MacOS/
181+
export PATH="$PWD:$PATH"
182+
cd -
183+
184+
# Run tests in browsers
185+
echo "Running CppInterOpTests in Firefox"
186+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" CppInterOpTests.html
187+
echo "Running DynamicLibraryManagerTests in Firefox"
188+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" DynamicLibraryManagerTests.html
189+
echo "Running CppInterOpTests in Google Chrome"
190+
emrun --browser="Google Chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" CppInterOpTests.html
191+
echo "Running DynamicLibraryManagerTests in Google Chrome"
192+
emrun --browser="Google Chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" DynamicLibraryManagerTests.html
193+
194+
cd ../../
148195
emmake make -j ${{ env.ncpus }} install
149196
150197
cd ..

.github/workflows/emscripten.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,93 @@ jobs:
599599
fi
600600
601601
emmake make -j ${{ env.ncpus }} check-cppinterop
602+
cd ./unittests/CppInterOp/
603+
# Fresh install browsers, and run Emscripten tests in them
604+
# This is to match the Emscripten build instructions, where
605+
# we run in a fresh browser, to stop any extra installed
606+
# stuff interferring with the running of the tests
607+
# Explaination of options for emrun
608+
# --browser (name of browser on path)
609+
# --kill_exit makes it so that when emrun finishes,
610+
# that the headless browser we create is killed along with it
611+
# --timeout 60 is such that emrun is killed after 60 seconds if
612+
# still running. emrun should have finished long before then,
613+
# so if it is still running, something went wrong (such as a test
614+
# which crashed the html file). This will cause the ci to fail,
615+
# as a non 0 value of will be returned.
616+
# In the case of Chrome we have the extra --no-sandbox flag, as on
617+
# Ubuntu Chrome will refuse to run otherwise, as it expects to have
618+
# been installed with admin privileges. This flag allows it to run
619+
# in userspace.
620+
os="${{ matrix.os }}"
621+
if [[ "${os}" == "macos"* ]]; then
622+
# Install Firefox
623+
wget "https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US" -O Firefox-latest.dmg
624+
hdiutil attach Firefox-latest.dmg
625+
cp -r /Volumes/Firefox/Firefox.app $PWD
626+
hdiutil detach /Volumes/Firefox
627+
cd ./Firefox.app/Contents/MacOS/
628+
export PATH="$PWD:$PATH"
629+
cd -
630+
631+
# Install Google Chrome
632+
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
633+
pkgutil --expand-full googlechrome.pkg google-chrome
634+
cd ./google-chrome/GoogleChrome.pkg/Payload/Google\ Chrome.app/Contents/MacOS/
635+
export PATH="$PWD:$PATH"
636+
cd -
637+
638+
# Run tests in browsers
639+
echo "Running CppInterOpTests in Firefox"
640+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" CppInterOpTests.html
641+
echo "Running DynamicLibraryManagerTests in Firefox"
642+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" DynamicLibraryManagerTests.html
643+
echo "Running CppInterOpTests in Google Chrome"
644+
emrun --browser="Google Chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" CppInterOpTests.html
645+
echo "Running DynamicLibraryManagerTests in Google Chrome"
646+
emrun --browser="Google Chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" DynamicLibraryManagerTests.html
647+
else
648+
export ARCHITECHURE=$(uname -m)
649+
if [[ "$ARCHITECHURE" != "aarch64" ]]; then
650+
# Install Google Chrome
651+
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
652+
dpkg-deb -x google-chrome-stable_current_amd64.deb $PWD/chrome
653+
cd ./chrome/opt/google/chrome/
654+
export PATH="$PWD:$PATH"
655+
cd -
656+
657+
# Install Firefox
658+
wget https://ftp.mozilla.org/pub/firefox/releases/138.0.1/linux-x86_64/en-GB/firefox-138.0.1.tar.xz
659+
tar -xJf firefox-138.0.1.tar.xz
660+
cd ./firefox
661+
export PATH="$PWD:$PATH"
662+
cd -
663+
664+
# Run tests in browsers
665+
echo "Running CppInterOpTests in Firefox"
666+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" CppInterOpTests.html
667+
echo "Running DynamicLibraryManagerTests in Firefox"
668+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" DynamicLibraryManagerTests.html
669+
echo "Running CppInterOpTests in Google Chrome"
670+
emrun --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" CppInterOpTests.html
671+
echo "Running DynamicLibraryManagerTests in Google Chrome"
672+
emrun --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" DynamicLibraryManagerTests.html
673+
else
674+
# Install Firefox
675+
wget https://ftp.mozilla.org/pub/firefox/releases/138.0.1/linux-aarch64/en-GB/firefox-138.0.1.tar.xz
676+
tar -xJf firefox-138.0.1.tar.xz
677+
cd ./firefox
678+
export PATH="$PWD:$PATH"
679+
cd -
680+
681+
# Run tests in browsers
682+
echo "Running CppInterOpTests in Firefox"
683+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" CppInterOpTests.html
684+
echo "Running DynamicLibraryManagerTests in Firefox"
685+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" DynamicLibraryManagerTests.html
686+
fi
687+
fi
688+
cd ../..
602689
emmake make -j ${{ env.ncpus }} install
603690
cd ..
604691

Emscripten-build-instructions.md

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ $env:CMAKE_PREFIX_PATH=$env:PREFIX
165165
$env:CMAKE_SYSTEM_PREFIX_PATH=$env:PREFIX
166166
```
167167

168-
on Windows. Now to build and test your Emscripten build of CppInterOp on Linux and osx execute the following
168+
on Windows. Now to build and test your Emscripten build of CppInterOp using node on Linux and osx execute the following
169169

170170
```bash
171171
mkdir build
@@ -182,7 +182,7 @@ emcmake cmake -DCMAKE_BUILD_TYPE=Release \
182182
emmake make -j $(nproc --all) check-cppinterop
183183
```
184184

185-
To build and test your Emscripten build of CppInterOp on Windows execute the following
185+
To build and test your Emscripten build of CppInterOp on using node Windows execute the following
186186

187187
```powershell
188188
emcmake cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} `
@@ -200,9 +200,85 @@ emcmake cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} `
200200
emmake make -j $(nproc --all) check-cppinterop
201201
```
202202

203+
It is possible to run the Emscripten tests in a headless browser on Linux and osx (in future we plan to include instructions on how to run the tests in a browser on Windows too). To do this we will first move to the tests directory
204+
205+
206+
```bash
207+
cd ./unittests/CppInterOp/
208+
```
209+
210+
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
211+
212+
```bash
213+
wget "https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US" -O Firefox-latest.dmg
214+
hdiutil attach Firefox-latest.dmg
215+
cp -r /Volumes/Firefox/Firefox.app $PWD
216+
hdiutil detach /Volumes/Firefox
217+
cd ./Firefox.app/Contents/MacOS/
218+
export PATH="$PWD:$PATH"
219+
cd -
220+
221+
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
222+
pkgutil --expand-full googlechrome.pkg google-chrome
223+
cd ./google-chrome/GoogleChrome.pkg/Payload/Google\ Chrome.app/Contents/MacOS/
224+
export PATH="$PWD:$PATH"
225+
cd -
226+
227+
echo "Running CppInterOpTests in Firefox"
228+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" CppInterOpTests.html
229+
echo "Running DynamicLibraryManagerTests in Firefox"
230+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" DynamicLibraryManagerTests.html
231+
echo "Running CppInterOpTests in Google Chrome"
232+
emrun --browser="Google Chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" CppInterOpTests.html
233+
echo "Running DynamicLibraryManagerTests in Google Chrome"
234+
emrun --browser="Google Chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" DynamicLibraryManagerTests.html
235+
```
236+
237+
To do this on Ubuntu x86 execute the following
238+
239+
```bash
240+
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
241+
dpkg-deb -x google-chrome-stable_current_amd64.deb $PWD/chrome
242+
cd ./chrome/opt/google/chrome/
243+
export PATH="$PWD:$PATH"
244+
cd -
245+
246+
wget https://ftp.mozilla.org/pub/firefox/releases/138.0.1/linux-x86_64/en-GB/firefox-138.0.1.tar.xz
247+
tar -xJf firefox-138.0.1.tar.xz
248+
cd ./firefox
249+
export PATH="$PWD:$PATH"
250+
cd -
251+
252+
echo "Running CppInterOpTests in Firefox"
253+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" CppInterOpTests.html
254+
echo "Running DynamicLibraryManagerTests in Firefox"
255+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" DynamicLibraryManagerTests.html
256+
echo "Running CppInterOpTests in Google Chrome"
257+
emrun --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" CppInterOpTests.html
258+
echo "Running DynamicLibraryManagerTests in Google Chrome"
259+
emrun --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" DynamicLibraryManagerTests.html
260+
```
261+
262+
and on Ubuntu Arm execute the following (Google Chrome is not available on Ubuntu arm,
263+
so we currently only run in Firefox on this platform, unlike other plaforms)
264+
265+
```bash
266+
wget https://ftp.mozilla.org/pub/firefox/releases/138.0.1/linux-aarch64/en-GB/firefox-138.0.1.tar.xz
267+
tar -xJf firefox-138.0.1.tar.xz
268+
cd ./firefox
269+
export PATH="$PWD:$PATH"
270+
cd -
271+
272+
echo "Running CppInterOpTests in Firefox"
273+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" CppInterOpTests.html
274+
echo "Running DynamicLibraryManagerTests in Firefox"
275+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" DynamicLibraryManagerTests.html
276+
```
277+
203278
Assuming it passes all test you can install by executing the following
204279

205280
```bash
281+
cd ../..
206282
emmake make -j $(nproc --all) install
207283
```
208284

docs/Emscripten-build-instructions.rst

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,80 @@ To build and test your Emscripten build of CppInterOp on Windows execute the fol
224224
..\
225225
emmake make -j $(nproc --all) check-cppinterop
226226
227+
It is possible to run the Emscripten tests in a headless browser on Linux and osx (in future we plan to include instructions on how to run the tests in a browser on Windows too). To do this we will first move to the tests directory
228+
229+
.. code:: bash
230+
231+
cd ./unittests/CppInterOp/
232+
233+
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
234+
235+
.. code:: bash
236+
237+
wget "https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US" -O Firefox-latest.dmg
238+
hdiutil attach Firefox-latest.dmg
239+
cp -r /Volumes/Firefox/Firefox.app $PWD
240+
hdiutil detach /Volumes/Firefox
241+
cd ./Firefox.app/Contents/MacOS/
242+
export PATH="$PWD:$PATH"
243+
cd -
244+
245+
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
246+
pkgutil --expand-full googlechrome.pkg google-chrome
247+
cd ./google-chrome/GoogleChrome.pkg/Payload/Google\ Chrome.app/Contents/MacOS/
248+
export PATH="$PWD:$PATH"
249+
cd -
250+
251+
echo "Running CppInterOpTests in Firefox"
252+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" CppInterOpTests.html
253+
echo "Running DynamicLibraryManagerTests in Firefox"
254+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" DynamicLibraryManagerTests.html
255+
echo "Running CppInterOpTests in Google Chrome"
256+
emrun --browser="Google Chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" CppInterOpTests.html
257+
echo "Running DynamicLibraryManagerTests in Google Chrome"
258+
emrun --browser="Google Chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" DynamicLibraryManagerTests.html
259+
260+
To do this on Ubuntu x86 execute the following
261+
262+
.. code:: bash
263+
264+
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
265+
dpkg-deb -x google-chrome-stable_current_amd64.deb $PWD/chrome
266+
cd ./chrome/opt/google/chrome/
267+
export PATH="$PWD:$PATH"
268+
cd -
269+
270+
wget https://ftp.mozilla.org/pub/firefox/releases/138.0.1/linux-x86_64/en-GB/firefox-138.0.1.tar.xz
271+
tar -xJf firefox-138.0.1.tar.xz
272+
cd ./firefox
273+
export PATH="$PWD:$PATH"
274+
cd -
275+
276+
echo "Running CppInterOpTests in Firefox"
277+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" CppInterOpTests.html
278+
echo "Running DynamicLibraryManagerTests in Firefox"
279+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" DynamicLibraryManagerTests.html
280+
echo "Running CppInterOpTests in Google Chrome"
281+
emrun --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" CppInterOpTests.html
282+
echo "Running DynamicLibraryManagerTests in Google Chrome"
283+
emrun --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" DynamicLibraryManagerTests.html
284+
285+
and on Ubuntu Arm execute the following (Google Chrome is not available on Ubuntu arm,
286+
so we currently only run the tests using Firefox on this platform, unlike other plaforms)
287+
288+
.. code:: bash
289+
290+
wget https://ftp.mozilla.org/pub/firefox/releases/138.0.1/linux-aarch64/en-GB/firefox-138.0.1.tar.xz
291+
tar -xJf firefox-138.0.1.tar.xz
292+
cd ./firefox
293+
export PATH="$PWD:$PATH"
294+
cd -
295+
296+
echo "Running CppInterOpTests in Firefox"
297+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" CppInterOpTests.html
298+
echo "Running DynamicLibraryManagerTests in Firefox"
299+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" DynamicLibraryManagerTests.html
300+
227301
Assuming it passes all test you can install by executing the following.
228302

229303
.. code:: bash

unittests/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ if(WIN32)
3434
else()
3535
target_link_libraries(${name} PRIVATE ${ARG_LIBRARIES} ${gtest_libs} ${link_pthreads_lib})
3636
endif()
37+
if(EMSCRIPTEN)
38+
# Without this cmake will try and get node to run the html file.
39+
# This guarantees that it runs the js file, and uses emsdks node.
40+
add_test(NAME cppinterop-${name} COMMAND $ENV{EMSDK_NODE} ${name}.js)
41+
else()
3742
add_test(NAME cppinterop-${name} COMMAND ${name})
43+
endif()
3844
set_tests_properties(cppinterop-${name} PROPERTIES
3945
TIMEOUT "${TIMEOUT_VALUE}"
4046
ENVIRONMENT "CPLUS_INCLUDE_PATH=${CMAKE_BINARY_DIR}/etc"

unittests/CppInterOp/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
if (EMSCRIPTEN)
2+
# So we create a html file, as well as the javascript file
3+
set(CMAKE_EXECUTABLE_SUFFIX ".html")
24
# Omitting CUDATest.cpp since Emscripten build currently has no GPU support
35
# For Emscripten builds linking to gtest_main will not suffice for gtest to run
46
# the tests and an explicitly main.cpp is needed
@@ -42,6 +44,10 @@ if(EMSCRIPTEN)
4244
#
4345
# --preload-file ${SYSROOT_PATH}/include@/include:
4446
# Preloads the system include directory into the Emscripten virtual filesystem to make headers accessible at runtime.
47+
#
48+
# --emrun
49+
# Makes it so that we run the html file created by this target, that we can capture the standard output
50+
# and output to the terminal
4551
target_link_options(CppInterOpTests
4652
PUBLIC "SHELL: -fexceptions"
4753
PUBLIC "SHELL: -s MAIN_MODULE=1"
@@ -50,6 +56,7 @@ if(EMSCRIPTEN)
5056
PUBLIC "SHELL: -s STACK_SIZE=32mb"
5157
PUBLIC "SHELL: -s INITIAL_MEMORY=128mb"
5258
PUBLIC "SHELL: --preload-file ${SYSROOT_PATH}/include@/include"
59+
PUBLIC "SHELL: --emrun"
5360
)
5461
endif()
5562

@@ -97,6 +104,7 @@ if(EMSCRIPTEN)
97104
PUBLIC "SHELL: -s STACK_SIZE=32mb"
98105
PUBLIC "SHELL: -s INITIAL_MEMORY=128mb"
99106
PUBLIC "SHELL: --preload-file ${SYSROOT_PATH}/include@/include"
107+
PUBLIC "SHELL: --emrun"
100108
)
101109
endif()
102110

0 commit comments

Comments
 (0)