Add test statmemprof/thread_exit_in_callback.

master
Jacques-Henri Jourdan 2020-05-11 17:10:13 +02:00
parent aa64e70bc1
commit 629fae6dc4
3 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,18 @@
(* TEST
modules = "thread_exit_in_callback_stub.c"
exit_status = "42"
* hassysthreads
include systhreads
** bytecode
** native
*)
(* We cannot tell Ocamltest that this program is supposed to stop with
a fatal error. Instead, we install a fatal error hook and call exit(42) *)
external install_fatal_error_hook : unit -> unit = "install_fatal_error_hook"
let _ =
install_fatal_error_hook ();
Gc.Memprof.(start ~callstack_size:10 ~sampling_rate:1.
{ null_tracker with alloc_minor = fun _ -> Thread.exit (); None });
ignore (Sys.opaque_identity (ref 1))

View File

@ -0,0 +1 @@
Fatal error hook: Thread.exit called from a memprof callback.

View File

@ -0,0 +1,16 @@
#include <stdio.h>
#include "caml/misc.h"
#include "caml/mlvalues.h"
void fatal_error_hook_exit_3 (char *msg, va_list args) {
fprintf(stderr, "Fatal error hook: ");
vfprintf(stderr, msg, args);
fprintf(stderr, "\n");
exit(42);
}
value install_fatal_error_hook (value unit) {
caml_fatal_error_hook = fatal_error_hook_exit_3;
return Val_unit;
}