forked from ocaml/ocaml
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add regression test emitting custom event from signal handler
- Loading branch information
1 parent
091934f
commit 63cf577
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
testsuite/tests/lib-runtime-events/test_user_event_signal.ml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
6 changes: 6 additions & 0 deletions
6
testsuite/tests/lib-runtime-events/test_user_event_signal.reference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |