Skip to content

Commit

Permalink
ocaml#9063 (cherry-pick commit 1b17cc4)
Browse files Browse the repository at this point in the history
Fix tests/backtrace/callstack.ml by changing the order of the content of that file. (ocaml#9063)

The original test had a race condition between finalization and thread preemption.
That was probably the cause for the wrong backtrace observed here:
ocaml#8641 (comment)
  • Loading branch information
jhjourdan authored and stedolan committed Mar 17, 2020
1 parent 1d5f54c commit b042b5b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
14 changes: 11 additions & 3 deletions testsuite/tests/backtrace/callstack.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,29 @@
include systhreads
compare_programs = "false"
** no-flambda
reference = "${test_source_directory}/callstack.reference"
*** native
*** bytecode
*)

let[@inline never] f0 () =
Printexc.print_raw_backtrace stdout (Printexc.get_callstack 100); ()
let[@inline never] f1 () = f0 (); ()
let[@inline never] f2 () = f1 (); ()
let[@inline never] f3 () = f2 (); ()

let () = Printf.printf "main thread:\n"
let () = f3 ()
let () = Printf.printf "new thread:\n"
let () = Thread.join (Thread.create f3 ())

let () = Printf.printf "from finalizer:\n"
let () =
Gc.finalise (fun _ -> f0 ()) [|1|];
Gc.full_major ();
()

(* We run this last, because the initialization of the thread library
starts the "tick thread", which periodically send a signal for
thread preemption. If the preempion occurs exactly when the
finalizer above runs, then a new row for [Thread.yield] appears in
the callstack, which breaks the test. *)
let () = Printf.printf "new thread:\n"
let () = Thread.join (Thread.create f3 ())
7 changes: 4 additions & 3 deletions testsuite/tests/backtrace/callstack.reference
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ Raised by primitive operation at file "callstack.ml", line 12, characters 38-66
Called from file "callstack.ml", line 13, characters 27-32
Called from file "callstack.ml", line 14, characters 27-32
Called from file "callstack.ml", line 15, characters 27-32
Called from file "callstack.ml", line 17, characters 9-14
Called from file "callstack.ml", line 18, characters 9-14
from finalizer:
Raised by primitive operation at file "callstack.ml", line 12, characters 38-66
Called from file "callstack.ml", line 23, characters 2-18
new thread:
Raised by primitive operation at file "callstack.ml", line 12, characters 38-66
Called from file "callstack.ml", line 13, characters 27-32
Called from file "callstack.ml", line 14, characters 27-32
Called from file "callstack.ml", line 15, characters 27-32
Called from file "thread.ml", line 39, characters 8-14
Raised by primitive operation at file "callstack.ml", line 12, characters 38-66
Called from file "callstack.ml", line 23, characters 2-18

0 comments on commit b042b5b

Please sign in to comment.