Skip to content

Commit

Permalink
Add regression test emitting custom event from signal handler
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierNicole committed Jan 23, 2024
1 parent 091934f commit 63cf577
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
31 changes: 31 additions & 0 deletions testsuite/tests/lib-runtime-events/test_user_event_signal.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
(* TEST
include runtime_events;
include unix;
*)

(* Check that emitting a custom event from a signal handler works (see #12900).
*)

let unit =
let encode _buf () =
print_endline "Start encoding event";
Unix.sleepf 1.5;
print_endline "Finished encoding event";
0
in
let decode _buf _len = () in
Runtime_events.Type.register ~encode ~decode

type Runtime_events.User.tag += My_event
let my_event = Runtime_events.User.register "event" My_event unit

let handle_signal _ =
print_endline "Signal handler called; writing trace event...";
Runtime_events.User.write my_event ()

let () =
Runtime_events.start ();
Sys.set_signal Sys.sigalrm (Signal_handle handle_signal);
ignore (Unix.alarm 1 : int);
Runtime_events.User.write my_event ();
print_endline "Done"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Start encoding event
Signal handler called; writing trace event...
Start encoding event
Finished encoding event
Finished encoding event
Done

0 comments on commit 63cf577

Please sign in to comment.