Skip to content

Commit

Permalink
Wasm_of_ocaml: fix the execution of tests in a sandbox (#11304)
Browse files Browse the repository at this point in the history
* Wasm: test sandboxing

Signed-off-by: Jérôme Vouillon <[email protected]>
  • Loading branch information
vouillon authored Jan 20, 2025
1 parent ad2ef5e commit 1ccb583
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/changes/11304.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Wasm_of_ocaml: fix the execution of tests in a sandbox. (#11304, @vouillon)
10 changes: 9 additions & 1 deletion src/dune_rules/inline_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,15 @@ include Sub_system.Register_end_point (struct
| Error _ -> Action_builder.return action
| Ok p -> Action_builder.path p >>> Action_builder.return action)
and+ () = deps
and+ () = Action_builder.path exe in
and+ () = Action_builder.path exe
and+ () =
match mode with
| Native | Best | Byte | Jsoo JS -> Action_builder.return ()
| Jsoo Wasm ->
Action_builder.path
(Path.build
(Path.Build.relative inline_test_dir (name ^ Js_of_ocaml.Ext.wasm_dir)))
in
Action.chdir (Path.build dir) action
in
let flags partition : string list Action_builder.t =
Expand Down
9 changes: 8 additions & 1 deletion src/dune_rules/test_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,14 @@ let rules (t : Tests.t) ~sctx ~dir ~scope ~expander ~dir_contents =
| None -> t.deps
| Some _ ->
Bindings.Unnamed (Dep_conf.File (String_with_vars.make_text loc test_exe))
:: t.deps
::
(match runtest_mode with
| `js Wasm ->
Bindings.Unnamed
(Dep_conf.File
(String_with_vars.make_text loc (s ^ Js_of_ocaml.Ext.wasm_dir)))
:: t.deps
| `js JS | `exe | `bc -> t.deps)
in
let add_alias ~loc ~action =
(* CR rgrinberg: why are we going through the stanza api? *)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 3.17)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(library
(name inline_test)
(modules inline_test)
(inline_tests
(modes wasm)
(backend inline_test_backend)))

(library
(name inline_test_backend)
(modules inline_test_backend)
(inline_tests.backend (generate_runner (echo ""))))
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions test/blackbox-tests/test-cases/wasmoo/sandboxing.t/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Run tests and inline tests within a sandbox in copy mode

$ dune runtest --sandbox=copy
3 changes: 3 additions & 0 deletions test/blackbox-tests/test-cases/wasmoo/sandboxing.t/test/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(test
(modes wasm)
(name test))
Empty file.

0 comments on commit 1ccb583

Please sign in to comment.