Skip to content

Commit 20e96b6

Browse files
committed
Run Emscripten tests in a browser
1 parent 90248d6 commit 20e96b6

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
@@ -542,6 +542,77 @@ jobs:
542542
fi
543543
544544
emmake make -j ${{ env.ncpus }} check-cppinterop
545+
cd ./unittests/CppInterOp/
546+
# Install browsers, and run Emscripten tests in them
547+
os="${{ matrix.os }}"
548+
if [[ "${os}" == "macos"* ]]; then
549+
# Install Firefox
550+
wget "https://download.mozilla.org/?product=firefox-latest&os=osx&lang=en-US" -O Firefox-latest.dmg
551+
hdiutil attach Firefox-latest.dmg
552+
cp -r /Volumes/Firefox/Firefox.app $PWD
553+
hdiutil detach /Volumes/Firefox
554+
cd ./Firefox.app/Contents/MacOS/
555+
export PATH="$PWD:$PATH"
556+
cd -
557+
558+
# Install Google Chrome
559+
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
560+
pkgutil --expand-full googlechrome.pkg google-chrome
561+
cd ./google-chrome/GoogleChrome.pkg/Payload/Google\ Chrome.app/Contents/MacOS/
562+
export PATH="$PWD:$PATH"
563+
cd -
564+
565+
# Run tests in browsers
566+
echo "Running CppInterOpTests in Firefox"
567+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" CppInterOpTests.html
568+
echo "Running DynamicLibraryManagerTests in Firefox"
569+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" DynamicLibraryManagerTests.html
570+
echo "Running CppInterOpTests in Google Chrome"
571+
emrun --browser="Google Chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" CppInterOpTests.html
572+
echo "Running DynamicLibraryManagerTests in Google Chrome"
573+
emrun --browser="Google Chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" DynamicLibraryManagerTests.html
574+
else
575+
export ARCHITECHURE=$(uname -m)
576+
if [[ "$ARCHITECHURE" != "aarch64" ]]; then
577+
# Install Google Chrome
578+
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
579+
dpkg-deb -x google-chrome-stable_current_amd64.deb $PWD/chrome
580+
cd ./chrome/opt/google/chrome/
581+
export PATH="$PWD:$PATH"
582+
cd -
583+
584+
# Install Firefox
585+
wget https://ftp.mozilla.org/pub/firefox/releases/138.0.1/linux-x86_64/en-GB/firefox-138.0.1.tar.xz
586+
tar -xJf firefox-138.0.1.tar.xz
587+
cd ./firefox
588+
export PATH="$PWD:$PATH"
589+
cd -
590+
591+
# Run tests in browsers
592+
echo "Running CppInterOpTests in Firefox"
593+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" CppInterOpTests.html
594+
echo "Running DynamicLibraryManagerTests in Firefox"
595+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" DynamicLibraryManagerTests.html
596+
echo "Running CppInterOpTests in Google Chrome"
597+
emrun --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" CppInterOpTests.html
598+
echo "Running DynamicLibraryManagerTests in Google Chrome"
599+
emrun --browser="google-chrome" --kill_exit --timeout 60 --browser-args="--headless --no-sandbox" DynamicLibraryManagerTests.html
600+
else
601+
# Install Firefox
602+
wget https://ftp.mozilla.org/pub/firefox/releases/138.0.1/linux-aarch64/en-GB/firefox-138.0.1.tar.xz
603+
tar -xJf firefox-138.0.1.tar.xz
604+
cd ./firefox
605+
export PATH="$PWD:$PATH"
606+
cd -
607+
608+
# Run tests in browsers
609+
echo "Running CppInterOpTests in Firefox"
610+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" CppInterOpTests.html
611+
echo "Running DynamicLibraryManagerTests in Firefox"
612+
emrun --browser="firefox" --kill_exit --timeout 60 --browser-args="--headless" DynamicLibraryManagerTests.html
613+
fi
614+
fi
615+
cd ../..
545616
emmake make -j ${{ env.ncpus }} install
546617
cd ..
547618

Emscripten-build-instructions.md

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

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

172172
```bash
173173
mkdir build
@@ -184,7 +184,7 @@ emcmake cmake -DCMAKE_BUILD_TYPE=Release \
184184
emmake make -j $(nproc --all) check-cppinterop
185185
```
186186

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

189189
```powershell
190190
emcmake cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} `
@@ -202,9 +202,85 @@ emcmake cmake -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} `
202202
emmake make -j $(nproc --all) check-cppinterop
203203
```
204204

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

207282
```bash
283+
cd ../..
208284
emmake make -j $(nproc --all) install
209285
```
210286

docs/Emscripten-build-instructions.rst

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

226300
.. 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)