File
Blob: src/workerd/server/tests/python/pytest/tests/test_dynlib_loading.py
| 1 | from pathlib import Path |
| 2 | |
| 3 | import pytest |
| 4 | |
| 5 | |
| 6 | def use(x): |
| 7 | pass |
| 8 | |
| 9 | |
| 10 | def test_dynlib_loading(tmp_path, monkeypatch): |
| 11 | # fmt: off |
| 12 | # The data here was produced as follows: |
| 13 | # |
| 14 | # touch a.c |
| 15 | # emcc -c a.c |
| 16 | # emcc a.o -o a.so -sSIDE_MODULE |
| 17 | # wasm-strip a.so -R target_features |
| 18 | # xxd -i a.so |
| 19 | # |
| 20 | # I used emcc 4.0.9. |
| 21 | Path(tmp_path / "a.so").write_bytes( |
| 22 | bytes( |
| 23 | [ |
| 24 | 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x08, 0x64, |
| 25 | 0x79, 0x6c, 0x69, 0x6e, 0x6b, 0x2e, 0x30, 0x01, 0x04, 0x00, 0x00, 0x00, |
| 26 | 0x00, 0x01, 0x04, 0x01, 0x60, 0x00, 0x00, 0x02, 0x38, 0x03, 0x03, 0x65, |
| 27 | 0x6e, 0x76, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x02, 0x00, 0x00, |
| 28 | 0x03, 0x65, 0x6e, 0x76, 0x0d, 0x5f, 0x5f, 0x6d, 0x65, 0x6d, 0x6f, 0x72, |
| 29 | 0x79, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x03, 0x7f, 0x00, 0x03, 0x65, 0x6e, |
| 30 | 0x76, 0x0c, 0x5f, 0x5f, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x62, 0x61, |
| 31 | 0x73, 0x65, 0x03, 0x7f, 0x00, 0x03, 0x02, 0x01, 0x00, 0x07, 0x15, 0x01, |
| 32 | 0x11, 0x5f, 0x5f, 0x77, 0x61, 0x73, 0x6d, 0x5f, 0x63, 0x61, 0x6c, 0x6c, |
| 33 | 0x5f, 0x63, 0x74, 0x6f, 0x72, 0x73, 0x00, 0x00, 0x0a, 0x04, 0x01, 0x02, |
| 34 | 0x00, 0x0b |
| 35 | ] |
| 36 | ) |
| 37 | ) |
| 38 | # fmt: on |
| 39 | monkeypatch.syspath_prepend(tmp_path) |
| 40 | with pytest.raises( |
| 41 | ImportError, match="Can only load shared libraries from read only file systems" |
| 42 | ): |
| 43 | import a |
| 44 | |
| 45 | use(a) |