diff --git a/.circleci/config.yml b/.circleci/config.yml index f18a4d52d..95cc75a0d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -149,6 +149,16 @@ jobs: command: | tools/pytest_wrapper.py packages/test* packages/*/test* -v -k chrome -n 2 + test-emsdk: + <<: *defaults + steps: + - attach_workspace: + at: . + - run: + name: test + command: | + pytest emsdk/tests -v + test-python: <<: *defaults steps: @@ -256,6 +266,9 @@ workflows: filters: tags: only: /.*/ + - test-emsdk: + requires: + - build-core - test-python: filters: tags: diff --git a/Makefile b/Makefile index 3384607e2..a5407f7ae 100644 --- a/Makefile +++ b/Makefile @@ -128,7 +128,7 @@ build/webworker_dev.js: src/webworker.js sed -i -e 's#{{ PYODIDE_BASE_URL }}#./#g' $@ test: all - pytest src packages/*/test* pyodide_build -v + pytest src emsdk/tests packages/*/test* pyodide_build -v lint: diff --git a/emsdk/patches/emulate_pointer.patch b/emsdk/patches/emulate_pointer.patch index 10469bc10..3989c97b1 100644 --- a/emsdk/patches/emulate_pointer.patch +++ b/emsdk/patches/emulate_pointer.patch @@ -4,6 +4,8 @@ enabled. This is a simple typo, since `mangled == "_" + symbol`. This piece of code is no longer present in upstream master, hence there is no effort to upstream the fix. +This patch is tested in emsdk/tests/test_emulate.py + diff --git a/emsdk/fastcomp/emscripten/src/library.js b/emsdk/fastcomp/emscripten/src/library.js index 97cca10..5c002d7 100644 --- a/emsdk/fastcomp/emscripten/src/library.js diff --git a/emsdk/tests/__init__.py b/emsdk/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/emsdk/tests/common.py b/emsdk/tests/common.py new file mode 100644 index 000000000..04a297c5a --- /dev/null +++ b/emsdk/tests/common.py @@ -0,0 +1,18 @@ +from pathlib import Path +import os + +EMSDK = Path(__file__).resolve().parents[1] / "emsdk" + +path = [ + str(EMSDK / "node" / "12.18.1_64bit" / "bin"), + str(EMSDK / "binaryen" / "bin"), + str(EMSDK / "fastcomp" / "emscripten"), +] + +env = { + "PATH": ":".join(path) + ":" + os.environ["PATH"], + "EMSDK": str(EMSDK), + "EM_CONFIG": str(EMSDK / ".emscripten"), + "EM_CACHE": str(EMSDK / ".emscripten_cache"), + "BINARYEN_ROOT": str(EMSDK / "binaryen"), +} diff --git a/emsdk/tests/test_emulate.py b/emsdk/tests/test_emulate.py new file mode 100644 index 000000000..2ee746ae9 --- /dev/null +++ b/emsdk/tests/test_emulate.py @@ -0,0 +1,75 @@ +import subprocess +from . import common + + +def test_emulate_function(tmpdir): + with tmpdir.as_cwd(): + with open("library.c", "w") as f: + f.write( + """\ +#include + +void foo() { + puts("hello from library"); +}""" + ) + with open("main.c", "w") as f: + f.write( + """\ +#include +#include + +int main() { + puts("hello from main"); + void *f = dlopen("library.wasm", RTLD_NOW); + if (!f) { + puts("cannot load side module"); + puts(dlerror()); + return 1; + } + typedef void (*voidfunc)(); + voidfunc g = (voidfunc) dlsym(f, "foo"); + if (!g) { + puts("cannot load side function"); + return 1; + } else { + g(); + } + return 0; +} +""" + ) + subprocess.run( + [ + "emcc", + "-s", + "SIDE_MODULE=1", + "library.c", + "-o", + "library.wasm", + "-s", + "EMULATE_FUNCTION_POINTER_CASTS=1", + "-s", + "EXPORT_ALL=1", + ], + check=True, + env=common.env, + ) + subprocess.run( + [ + "emcc", + "-s", + "MAIN_MODULE=1", + "main.c", + "--embed-file", + "library.wasm", + "-s", + "EMULATE_FUNCTION_POINTER_CASTS=1", + ], + check=True, + env=common.env, + ) + out = subprocess.run( + ["node", "a.out.js"], capture_output=True, check=True, env=common.env + ) + assert out.stdout == b"hello from main\nhello from library\n"