Test emsdk patches (#905)

This commit is contained in:
Dexter Chua 2020-12-21 11:20:11 +08:00 committed by GitHub
parent 93e547a2b5
commit 77b2a99697
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 109 additions and 1 deletions

View File

@ -149,6 +149,16 @@ jobs:
command: | command: |
tools/pytest_wrapper.py packages/test* packages/*/test* -v -k chrome -n 2 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: test-python:
<<: *defaults <<: *defaults
steps: steps:
@ -256,6 +266,9 @@ workflows:
filters: filters:
tags: tags:
only: /.*/ only: /.*/
- test-emsdk:
requires:
- build-core
- test-python: - test-python:
filters: filters:
tags: tags:

View File

@ -128,7 +128,7 @@ build/webworker_dev.js: src/webworker.js
sed -i -e 's#{{ PYODIDE_BASE_URL }}#./#g' $@ sed -i -e 's#{{ PYODIDE_BASE_URL }}#./#g' $@
test: all test: all
pytest src packages/*/test* pyodide_build -v pytest src emsdk/tests packages/*/test* pyodide_build -v
lint: lint:

View File

@ -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 code is no longer present in upstream master, hence there is no effort to
upstream the fix. 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 diff --git a/emsdk/fastcomp/emscripten/src/library.js b/emsdk/fastcomp/emscripten/src/library.js
index 97cca10..5c002d7 100644 index 97cca10..5c002d7 100644
--- a/emsdk/fastcomp/emscripten/src/library.js --- a/emsdk/fastcomp/emscripten/src/library.js

0
emsdk/tests/__init__.py Normal file
View File

18
emsdk/tests/common.py Normal file
View File

@ -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"),
}

View File

@ -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 <stdio.h>
void foo() {
puts("hello from library");
}"""
)
with open("main.c", "w") as f:
f.write(
"""\
#include <stdio.h>
#include <dlfcn.h>
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"