Skip to content

Commit b26b2bd

Browse files
authored
OCaml 5: restore nnp tests (#267)
* Restore NNP tests * Restore some additional tests
1 parent 216f730 commit b26b2bd

File tree

13 files changed

+116
-0
lines changed

13 files changed

+116
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(* TEST *)
2+
3+
(* Ensure that a bound which is negative on 31-bit OCaml but positive on 32-bit
4+
OCaml produces the same result on 64-bit OCaml. *)
5+
let bound = 0x6FFFFFFF in
6+
if bound < 0 then (* 31-bit integers *)
7+
print_endline "6beb775a"
8+
else (* 32 or 64-bit integers *)
9+
let s = Random.State.make [| 42 |] in
10+
Printf.printf "%x\n" (Random.State.full_int s bound)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6beb775a

testsuite/tests/lib-string/test_string.reference

Whitespace-only changes.

testsuite/tests/lib-threads/pr9971.ml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
(* TEST
2+
3+
* hassysthreads
4+
include systhreads
5+
** bytecode
6+
** native
7+
8+
*)
9+
10+
let t =
11+
let t = Thread.create (fun _ -> ())() in
12+
Thread.join t
13+
14+
let () =
15+
Thread.exit ()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <string.h>
2+
#include "caml/mlvalues.h"
3+
#include "caml/gc.h"
4+
#include "caml/memory.h"
5+
6+
static int colors[4] = { Caml_white, Caml_gray, Caml_blue, Caml_black };
7+
8+
value make_block(value header_size, value color, value size)
9+
{
10+
intnat sz = Nativeint_val(size);
11+
value * p = caml_stat_alloc((1 + sz) * sizeof(value));
12+
p[0] = Make_header(Nativeint_val(header_size), 0, colors[Int_val(color)]);
13+
memset(p + 1, 0x80, sz * sizeof(value));
14+
return (value) (p + 1);
15+
}
16+
17+
value make_raw_pointer (value v)
18+
{
19+
return (value) Nativeint_val(v);
20+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
type color = White | Gray | Blue | Black
2+
3+
external make_block: nativeint -> color -> nativeint -> Obj.t
4+
= "make_block"
5+
6+
external make_raw_pointer: nativeint -> Obj.t
7+
= "make_raw_pointer"
8+
9+
let do_gc root =
10+
Gc.compact(); (* full major + compaction *)
11+
root
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(* TEST
2+
modules = "cstubs.c np.ml"
3+
* bytecode
4+
* native
5+
*)
6+
7+
open Np
8+
9+
(* Out-of-heap object with black header is accepted even in no-naked-pointers
10+
mode. GC doesn't scan black objects. *)
11+
12+
let x = do_gc [ make_block 100n Black 100n ]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(* TEST
2+
modules = "cstubs.c np.ml"
3+
* bytecode
4+
* native
5+
*)
6+
7+
open Np
8+
9+
(* Out-of-heap object with black header is accepted even in no-naked-pointers
10+
mode. GC doesn't scan black objects. However, if the size in the
11+
head is crazily big, the naked pointer detector will warn. *)
12+
13+
let x = do_gc [ make_block (-1n) Black 100n ]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
exec ${test_source_directory}/runtest.sh
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
(* TEST
2+
modules = "cstubs.c np.ml"
3+
* naked_pointers
4+
** bytecode
5+
** native
6+
*)
7+
8+
open Np
9+
10+
(* Out-of-heap object with non-black header is OK in naked pointers mode only *)
11+
(* Note that the header size can be wrong as it should not be used by the GC *)
12+
13+
let x = do_gc [ make_block 10000n White 10n;
14+
make_block 1n Blue 0n;
15+
make_block (-1n) Gray 5n ]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
exec ${test_source_directory}/runtest.sh
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
exec ${test_source_directory}/runtest.sh
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
if grep -q "#define NAKED_POINTERS_CHECKER" ${ocamlsrcdir}/runtime/caml/m.h \
4+
&& (echo ${program} | grep -q '\.opt')
5+
then
6+
(${program} > ${output}) 2>&1 | grep -q '^Out-of-heap '
7+
exit $?
8+
else
9+
exec ${program} > ${output}
10+
fi

0 commit comments

Comments
 (0)