Skip to content

Commit

Permalink
Merge pull request #56 from Engil/engil/add_test_dynlink_backtrace
Browse files Browse the repository at this point in the history
testsuite: add tests for dynlink and stack unwinding
  • Loading branch information
ctk21 committed Mar 17, 2021
2 parents 17fa2e1 + 666296e commit 0d9140e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
42 changes: 42 additions & 0 deletions testsuite/tests/backtrace/backtrace_dynlink.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
(* TEST
include dynlink
files = "backtrace_dynlink_plugin.ml"
libraries = ""
* shared-libraries
** native-dynlink
*** setup-ocamlopt.byte-build-env
**** ocamlopt.byte
module = "backtrace_dynlink.ml"
flags = "-g"
**** ocamlopt.byte
program = "backtrace_dynlink_plugin.cmxs"
flags = "-shared -g"
all_modules = "backtrace_dynlink_plugin.ml"
**** ocamlopt.byte
program = "${test_build_directory}/main.exe"
libraries = "dynlink"
all_modules = "backtrace_dynlink.cmx"
***** run
ocamlrunparam += ",b=1"
****** check-program-output
*)

(* test for backtrace and stack unwinding with dynlib. *)
(* https://github.com/ocaml-multicore/ocaml-multicore/issues/440 *)
(* https://github.com/ocaml-multicore/ocaml-multicore/pull/499 *)

let () =
Dynlink.allow_unsafe_modules true;
try
Dynlink.loadfile "backtrace_dynlink_plugin.cmxs"
with
| Dynlink.Error err ->
print_endline @@ Dynlink.error_message err;
Printexc.print_backtrace stdout;
| exn ->
Printexc.to_string exn |> print_endline;
print_endline "ERROR"
18 changes: 18 additions & 0 deletions testsuite/tests/backtrace/backtrace_dynlink.reference
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Raised by primitive operation at Backtrace_dynlink_plugin in file "backtrace_dynlink_plugin.ml", line 6, characters 13-38
Called from Dynlink.Native.run.(fun) in file "otherlibs/dynlink/native/dynlink.ml", line 85, characters 12-29
Called from Stdlib__list.iter in file "list.ml", line 110, characters 12-15
Called from Dynlink_common.Make.load.(fun) in file "otherlibs/dynlink/dynlink_common.ml", line 347, characters 13-44
Called from Stdlib__list.iter in file "list.ml", line 110, characters 12-15
Called from Dynlink_common.Make.load in file "otherlibs/dynlink/dynlink_common.ml", line 345, characters 8-240
Called from Dynlink_common.Make.loadfile in file "otherlibs/dynlink/dynlink_common.ml" (inlined), line 357, characters 26-45
Called from Backtrace_dynlink in file "backtrace_dynlink.ml", line 35, characters 4-52
execution of module initializers in the shared library failed: Failure("SUCCESS")
Raised by primitive operation at Dynlink.Native.run.(fun) in file "otherlibs/dynlink/native/dynlink.ml", line 85, characters 12-29
Re-raised at Dynlink.Native.run.(fun) in file "otherlibs/dynlink/native/dynlink.ml", line 87, characters 10-149
Called from Stdlib__list.iter in file "list.ml", line 110, characters 12-15
Called from Dynlink_common.Make.load.(fun) in file "otherlibs/dynlink/dynlink_common.ml", line 347, characters 13-44
Called from Stdlib__list.iter in file "list.ml", line 110, characters 12-15
Called from Dynlink_common.Make.load in file "otherlibs/dynlink/dynlink_common.ml", line 345, characters 8-240
Re-raised at Dynlink_common.Make.load in file "otherlibs/dynlink/dynlink_common.ml", line 355, characters 8-17
Called from Dynlink_common.Make.loadfile in file "otherlibs/dynlink/dynlink_common.ml" (inlined), line 357, characters 26-45
Called from Backtrace_dynlink in file "backtrace_dynlink.ml", line 35, characters 4-52
8 changes: 8 additions & 0 deletions testsuite/tests/backtrace/backtrace_dynlink_plugin.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let () =
try
failwith "SUCCESS"
with
| e ->
let c = Printexc.get_callstack 10 in
Printexc.print_raw_backtrace stdout c;
raise e

0 comments on commit 0d9140e

Please sign in to comment.