Skip to content

Commit 412db98

Browse files
committed
Improve testcase
Make sure that the printing functions do not interfere with the polling.
1 parent 3686ced commit 412db98

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

testsuite/tests/c-api/alloc_async.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66
The C stub itself contains more details on the mechanism. *)
77

88
external test : int ref -> unit = "stub"
9+
external print_status : string -> int -> unit = "print_status_caml" [@@noalloc]
910

1011
let f () =
1112
let r = ref 42 in
1213
Gc.finalise (fun s -> r := !s) (ref 17);
13-
Printf.printf "OCaml, before: %d\n%!" !r;
14+
print_status "OCaml, before" !r;
1415
test r;
15-
Printf.printf "OCaml, after: %d\n%!" !r;
16+
print_status "OCaml, after" !r;
1617
ignore (Sys.opaque_identity (ref 100));
17-
Printf.printf "OCaml, after alloc: %d\n%!" !r;
18+
print_status "OCaml, after alloc" !r;
1819
()
1920

2021
let () = (f [@inlined never]) ()

testsuite/tests/c-api/alloc_async_stubs.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,27 @@
55
#define CAML_INTERNALS
66
#include "caml/gc_ctrl.h"
77

8+
9+
void print_status(const char *str, int n)
10+
{
11+
printf("%s: %d\n", str, n);
12+
fflush(stdout);
13+
}
14+
15+
value print_status_caml(value str, value n)
16+
{
17+
print_status(String_val(str), Int_val(n));
18+
return Val_unit;
19+
}
20+
821
const char* strs[] = { "foo", "bar", 0 };
922
value stub(value ref)
1023
{
1124
CAMLparam1(ref);
1225
CAMLlocal2(x, y);
1326
char* s; intnat coll_before;
1427

15-
printf("C, before: %d\n", Int_val(Field(ref, 0)));
28+
print_status("C, before", Int_val(Field(ref, 0)));
1629

1730
/* First, do enough major allocations to do a full major collection cycle */
1831
coll_before = caml_stat_major_collections;
@@ -50,7 +63,6 @@ value stub(value ref)
5063
free(s);
5164

5265

53-
printf("C, after: %d\n", Int_val(Field(ref, 0)));
54-
fflush(stdout);
66+
print_status("C, after", Int_val(Field(ref, 0)));
5567
CAMLreturn (Val_unit);
5668
}

0 commit comments

Comments
 (0)