Skip to content

Commit c729bc4

Browse files
committed
Run Emscripten tests in a browser
1 parent 2595a1f commit c729bc4

File tree

6 files changed

+259
-2
lines changed

6 files changed

+259
-2
lines changed

.github/workflows/deploy-pages.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,35 @@ jobs:
145145
../
146146
fi
147147
emmake make -j ${{ env.ncpus }} check-cppinterop
148+
cd ./unittests/CppInterOp/
149+
150+
# Install Firefox
151+
wget "https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US" -O Firefox-latest.dmg
152+
hdiutil attach Firefox-latest.dmg
153+
cp -r /Volumes/Firefox/Firefox.app $PWD
154+
hdiutil detach /Volumes/Firefox
155+
cd ./Firefox.app/Contents/MacOS/
156+
export PATH="$PWD:$PATH"
157+
cd -
158+
159+
# Install Google Chrome
160+
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
161+
pkgutil --expand-full googlechrome.pkg google-chrome
162+
cd ./google-chrome/GoogleChrome.pkg/Payload/Google\ Chrome.app/Contents/MacOS/
163+
export PATH="$PWD:$PATH"
164+
cd -
165+
166+
# Run tests in browsers
167+
echo "Running CppInterOpTests in Firefox"
168+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" CppInterOpTests.html
169+
echo "Running DynamicLibraryManagerTests in Firefox"
170+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" DynamicLibraryManagerTests.html
171+
echo "Running CppInterOpTests in Google Chrome"
172+
emrun --browser="Google Chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" CppInterOpTests.html
173+
echo "Running DynamicLibraryManagerTests in Google Chrome"
174+
emrun --browser="Google Chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" DynamicLibraryManagerTests.html
175+
176+
cd ../../
148177
emmake make -j ${{ env.ncpus }} install
149178
150179
cd ..

.github/workflows/emscripten.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,77 @@ jobs:
599599
fi
600600
601601
emmake make -j ${{ env.ncpus }} check-cppinterop
602+
cd ./unittests/CppInterOp/
603+
# Install browsers, and run Emscripten tests in them
604+
os="${{ matrix.os }}"
605+
if [[ "${os}" == "macos"* ]]; then
606+
# Install Firefox
607+
wget "https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US" -O Firefox-latest.dmg
608+
hdiutil attach Firefox-latest.dmg
609+
cp -r /Volumes/Firefox/Firefox.app $PWD
610+
hdiutil detach /Volumes/Firefox
611+
cd ./Firefox.app/Contents/MacOS/
612+
export PATH="$PWD:$PATH"
613+
cd -
614+
615+
# Install Google Chrome
616+
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
617+
pkgutil --expand-full googlechrome.pkg google-chrome
618+
cd ./google-chrome/GoogleChrome.pkg/Payload/Google\ Chrome.app/Contents/MacOS/
619+
export PATH="$PWD:$PATH"
620+
cd -
621+
622+
# Run tests in browsers
623+
echo "Running CppInterOpTests in Firefox"
624+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" CppInterOpTests.html
625+
echo "Running DynamicLibraryManagerTests in Firefox"
626+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" DynamicLibraryManagerTests.html
627+
echo "Running CppInterOpTests in Google Chrome"
628+
emrun --browser="Google Chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" CppInterOpTests.html
629+
echo "Running DynamicLibraryManagerTests in Google Chrome"
630+
emrun --browser="Google Chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" DynamicLibraryManagerTests.html
631+
else
632+
export ARCHITECHURE=$(uname -m)
633+
if [[ "$ARCHITECHURE" != "aarch64" ]]; then
634+
# Install Google Chrome
635+
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
636+
dpkg-deb -x google-chrome-stable_current_amd64.deb $PWD/chrome
637+
cd ./chrome/opt/google/chrome/
638+
export PATH="$PWD:$PATH"
639+
cd -
640+
641+
# Install Firefox
642+
wget https://ftp.mozilla.org/pub/firefox/releases/138.0.1/linux-x86_64/en-GB/firefox-138.0.1.tar.xz
643+
tar -xJf firefox-138.0.1.tar.xz
644+
cd ./firefox
645+
export PATH="$PWD:$PATH"
646+
cd -
647+
648+
# Run tests in browsers
649+
echo "Running CppInterOpTests in Firefox"
650+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" CppInterOpTests.html
651+
echo "Running DynamicLibraryManagerTests in Firefox"
652+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" DynamicLibraryManagerTests.html
653+
echo "Running CppInterOpTests in Google Chrome"
654+
emrun --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" CppInterOpTests.html
655+
echo "Running DynamicLibraryManagerTests in Google Chrome"
656+
emrun --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" DynamicLibraryManagerTests.html
657+
else
658+
# Install Firefox
659+
wget https://ftp.mozilla.org/pub/firefox/releases/138.0.1/linux-aarch64/en-GB/firefox-138.0.1.tar.xz
660+
tar -xJf firefox-138.0.1.tar.xz
661+
cd ./firefox
662+
export PATH="$PWD:$PATH"
663+
cd -
664+
665+
# Run tests in browsers
666+
echo "Running CppInterOpTests in Firefox"
667+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" CppInterOpTests.html
668+
echo "Running DynamicLibraryManagerTests in Firefox"
669+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" DynamicLibraryManagerTests.html
670+
fi
671+
fi
672+
cd ../..
602673
emmake make -j ${{ env.ncpus }} install
603674
cd ..
604675

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
@@ -220,6 +220,80 @@ To build and test your Emscripten build of CppInterOp on Windows execute the fol
220220
..\
221221
emmake make -j $(nproc --all) check-cppinterop
222222
223+
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
224+
225+
.. code:: bash
226+
227+
cd ./unittests/CppInterOp/
228+
229+
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
230+
231+
.. code:: bash
232+
233+
wget "https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US" -O Firefox-latest.dmg
234+
hdiutil attach Firefox-latest.dmg
235+
cp -r /Volumes/Firefox/Firefox.app $PWD
236+
hdiutil detach /Volumes/Firefox
237+
cd ./Firefox.app/Contents/MacOS/
238+
export PATH="$PWD:$PATH"
239+
cd -
240+
241+
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
242+
pkgutil --expand-full googlechrome.pkg google-chrome
243+
cd ./google-chrome/GoogleChrome.pkg/Payload/Google\ Chrome.app/Contents/MacOS/
244+
export PATH="$PWD:$PATH"
245+
cd -
246+
247+
echo "Running CppInterOpTests in Firefox"
248+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" CppInterOpTests.html
249+
echo "Running DynamicLibraryManagerTests in Firefox"
250+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" DynamicLibraryManagerTests.html
251+
echo "Running CppInterOpTests in Google Chrome"
252+
emrun --browser="Google Chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" CppInterOpTests.html
253+
echo "Running DynamicLibraryManagerTests in Google Chrome"
254+
emrun --browser="Google Chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" DynamicLibraryManagerTests.html
255+
256+
To do this on Ubuntu x86 execute the following
257+
258+
.. code:: bash
259+
260+
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
261+
dpkg-deb -x google-chrome-stable_current_amd64.deb $PWD/chrome
262+
cd ./chrome/opt/google/chrome/
263+
export PATH="$PWD:$PATH"
264+
cd -
265+
266+
wget https://ftp.mozilla.org/pub/firefox/releases/138.0.1/linux-x86_64/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+
echo "Running CppInterOpTests in Google Chrome"
277+
emrun --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" CppInterOpTests.html
278+
echo "Running DynamicLibraryManagerTests in Google Chrome"
279+
emrun --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" DynamicLibraryManagerTests.html
280+
281+
and on Ubuntu Arm execute the following (Google Chrome is not available on Ubuntu arm,
282+
so we currently only run the tests using Firefox on this platform, unlike other plaforms)
283+
284+
.. code:: bash
285+
286+
wget https://ftp.mozilla.org/pub/firefox/releases/138.0.1/linux-aarch64/en-GB/firefox-138.0.1.tar.xz
287+
tar -xJf firefox-138.0.1.tar.xz
288+
cd ./firefox
289+
export PATH="$PWD:$PATH"
290+
cd -
291+
292+
echo "Running CppInterOpTests in Firefox"
293+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" CppInterOpTests.html
294+
echo "Running DynamicLibraryManagerTests in Firefox"
295+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" DynamicLibraryManagerTests.html
296+
223297
Assuming it passes all test you can install by executing the following.
224298

225299
.. code:: bash

unittests/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ if(WIN32)
3434
else()
3535
target_link_libraries(${name} PRIVATE ${ARG_LIBRARIES} ${gtest_libs} ${link_pthreads_lib})
3636
endif()
37+
if(EMSCRIPTEN)
38+
add_test(NAME cppinterop-${name} COMMAND $ENV{EMSDK_NODE} ${name}.js)
39+
else()
3740
add_test(NAME cppinterop-${name} COMMAND ${name})
41+
endif()
3842
set_tests_properties(cppinterop-${name} PROPERTIES
3943
TIMEOUT "${TIMEOUT_VALUE}"
4044
ENVIRONMENT "CPLUS_INCLUDE_PATH=${CMAKE_BINARY_DIR}/etc"

unittests/CppInterOp/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
if (EMSCRIPTEN)
2+
set(CMAKE_EXECUTABLE_SUFFIX ".html")
23
# Omitting CUDATest.cpp since Emscripten build currently has no GPU support
34
# For Emscripten builds linking to gtest_main will not suffice for gtest to run
45
# the tests and an explicitly main.cpp is needed
@@ -50,6 +51,7 @@ if(EMSCRIPTEN)
5051
PUBLIC "SHELL: -s STACK_SIZE=32mb"
5152
PUBLIC "SHELL: -s INITIAL_MEMORY=128mb"
5253
PUBLIC "SHELL: --preload-file ${SYSROOT_PATH}/include@/include"
54+
PUBLIC "SHELL: --emrun"
5355
)
5456
endif()
5557

@@ -97,6 +99,7 @@ if(EMSCRIPTEN)
9799
PUBLIC "SHELL: -s STACK_SIZE=32mb"
98100
PUBLIC "SHELL: -s INITIAL_MEMORY=128mb"
99101
PUBLIC "SHELL: --preload-file ${SYSROOT_PATH}/include@/include"
102+
PUBLIC "SHELL: --emrun"
100103
)
101104
endif()
102105

0 commit comments

Comments
 (0)