Skip to content

Commit

Permalink
Update tests to use bigarray-compat package instead of bigarray
Browse files Browse the repository at this point in the history
  • Loading branch information
dinosaure committed Nov 12, 2020
1 parent b5aa5bc commit aeade51
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 148 deletions.
153 changes: 77 additions & 76 deletions Makefile.tests

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tests/test-alignment/test_alignment.ml
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ let test_struct_tail_padding _ =
*)
let test_bigarray_alignment _ =
let module M = struct
module B = Bigarray
type k = K : ('a, 'b) Bigarray.kind * int -> k
module B = Bigarray_compat
type k = K : ('a, 'b) Bigarray_compat.kind * int -> k
let kind_alignments = [
K (B.float32, alignment float);
K (B.float64, alignment double);
Expand Down
54 changes: 27 additions & 27 deletions tests/test-bigarrays/test_bigarrays.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type 'a std_array = 'a array

open OUnit2
open Ctypes
module BA = Bigarray
module BA = Bigarray_compat


let array_of_list2 typ list2 =
Expand Down Expand Up @@ -325,34 +325,34 @@ let test_ctypes_array_of_bigarray _ =
*)
let test_fortran_layout_bigarrays _ =
(* array1 *)
let a1c = bigarray_of_array array1 Bigarray.int32
let a1c = bigarray_of_array array1 Bigarray_compat.int32
(CArray.of_list int32_t [10l; 20l; 30l; 40l]) in
let p1 = bigarray_start array1 a1c in
let a1f = fortran_bigarray_of_ptr array1 4 Bigarray.int32 p1 in
let a1f = fortran_bigarray_of_ptr array1 4 Bigarray_compat.int32 p1 in
begin
assert_equal 4 (Bigarray.Array1.dim a1f);
assert_equal Bigarray.int32 (Bigarray.Array1.kind a1f);
assert_equal Bigarray.fortran_layout (Bigarray.Array1.layout a1f);
assert_equal 4 (Bigarray_compat.Array1.dim a1f);
assert_equal Bigarray_compat.int32 (Bigarray_compat.Array1.kind a1f);
assert_equal Bigarray_compat.fortran_layout (Bigarray_compat.Array1.layout a1f);
assert_equal a1f.{1} 10l;
assert_equal a1f.{2} 20l;
assert_equal a1f.{3} 30l;
assert_equal a1f.{4} 40l;
end;

(* array2 *)
let a2c = bigarray_of_array array2 Bigarray.int32
let a2c = bigarray_of_array array2 Bigarray_compat.int32
(CArray.of_list (array 2 int32_t)
[CArray.of_list int32_t [10l; 20l];
CArray.of_list int32_t [30l; 40l];
CArray.of_list int32_t [50l; 60l];
CArray.of_list int32_t [70l; 80l]]) in
let p2 = bigarray_start array2 a2c in
let a2f = fortran_bigarray_of_ptr array2 (4,2) Bigarray.int32 p2 in
let a2f = fortran_bigarray_of_ptr array2 (4,2) Bigarray_compat.int32 p2 in
begin
assert_equal 4 (Bigarray.Array2.dim1 a2f);
assert_equal 2 (Bigarray.Array2.dim2 a2f);
assert_equal Bigarray.int32 (Bigarray.Array2.kind a2f);
assert_equal Bigarray.fortran_layout (Bigarray.Array2.layout a2f);
assert_equal 4 (Bigarray_compat.Array2.dim1 a2f);
assert_equal 2 (Bigarray_compat.Array2.dim2 a2f);
assert_equal Bigarray_compat.int32 (Bigarray_compat.Array2.kind a2f);
assert_equal Bigarray_compat.fortran_layout (Bigarray_compat.Array2.layout a2f);
assert_equal a2f.{1,1} 10l;
assert_equal a2f.{2,1} 20l;
assert_equal a2f.{3,1} 30l;
Expand All @@ -365,27 +365,27 @@ let test_fortran_layout_bigarrays _ =
end;

(* genarray *)
let agc = bigarray_of_array genarray Bigarray.int32
let agc = bigarray_of_array genarray Bigarray_compat.int32
(CArray.of_list int32_t
[10l; 20l;
30l; 40l;
50l; 60l;
70l; 80l]) in
let pg = bigarray_start genarray agc in
let agf = fortran_bigarray_of_ptr genarray [|4;2|] Bigarray.int32 pg in
let agf = fortran_bigarray_of_ptr genarray [|4;2|] Bigarray_compat.int32 pg in
begin
assert_equal [|4;2|] (Bigarray.Genarray.dims agf);
assert_equal Bigarray.int32 (Bigarray.Genarray.kind agf);
assert_equal Bigarray.fortran_layout (Bigarray.Genarray.layout agf);
assert_equal (Bigarray.Genarray.get agf [|1;1|]) 10l;
assert_equal (Bigarray.Genarray.get agf [|2;1|]) 20l;
assert_equal (Bigarray.Genarray.get agf [|3;1|]) 30l;
assert_equal (Bigarray.Genarray.get agf [|4;1|]) 40l;

assert_equal (Bigarray.Genarray.get agf [|1;2|]) 50l;
assert_equal (Bigarray.Genarray.get agf [|2;2|]) 60l;
assert_equal (Bigarray.Genarray.get agf [|3;2|]) 70l;
assert_equal (Bigarray.Genarray.get agf [|4;2|]) 80l;
assert_equal [|4;2|] (Bigarray_compat.Genarray.dims agf);
assert_equal Bigarray_compat.int32 (Bigarray_compat.Genarray.kind agf);
assert_equal Bigarray_compat.fortran_layout (Bigarray_compat.Genarray.layout agf);
assert_equal (Bigarray_compat.Genarray.get agf [|1;1|]) 10l;
assert_equal (Bigarray_compat.Genarray.get agf [|2;1|]) 20l;
assert_equal (Bigarray_compat.Genarray.get agf [|3;1|]) 30l;
assert_equal (Bigarray_compat.Genarray.get agf [|4;1|]) 40l;

assert_equal (Bigarray_compat.Genarray.get agf [|1;2|]) 50l;
assert_equal (Bigarray_compat.Genarray.get agf [|2;2|]) 60l;
assert_equal (Bigarray_compat.Genarray.get agf [|3;2|]) 70l;
assert_equal (Bigarray_compat.Genarray.get agf [|4;2|]) 80l;
end


Expand Down Expand Up @@ -464,7 +464,7 @@ let test_bigarray_lifetime_with_ctypes_reference _ =
let () =
let pointer =
(* Allocate a bigarray and attach a ctypes pointer *)
let ba = Bigarray.(Array2.create int c_layout) 1024 1024 in
let ba = Bigarray_compat.(Array2.create int c_layout) 1024 1024 in
begin
ba.{0,0} <- 1;
Gc.finalise finalise ba;
Expand Down
32 changes: 16 additions & 16 deletions tests/test-coercions/test_coercions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ let test_pointer_coercions _ =
T complex64;
T (ptr double);
T string;
T (bigarray array1 10 Bigarray.int32);
T (bigarray array1 10 Bigarray_compat.int32);
T (array 5 int32_t);
T (structure "s");
T (union "u");
Expand Down Expand Up @@ -184,83 +184,83 @@ let test_unsupported_coercions _ =
type boxed_type = T : 'a typ -> boxed_type
let types = [
T int8_t,
[T uint16_t; T float; T complex64; T (bigarray array1 10 Bigarray.int32);
[T uint16_t; T float; T complex64; T (bigarray array1 10 Bigarray_compat.int32);
T (array 5 int32_t); T (structure "s"); T (union "u");
T (abstract ~name:"a" ~size:12 ~alignment:4)];

T uint16_t,
[T int8_t; T int; T float; T short; T complex64;
T (bigarray array1 10 Bigarray.int32); T (array 5 int32_t);
T (bigarray array1 10 Bigarray_compat.int32); T (array 5 int32_t);
T (structure "s"); T (union "u");
T (abstract ~name:"a" ~size:12 ~alignment:4)];

T int,
[T uint16_t; T float; T complex64; T (bigarray array1 10 Bigarray.int32);
[T uint16_t; T float; T complex64; T (bigarray array1 10 Bigarray_compat.int32);
T (array 5 int32_t); T (structure "s"); T (union "u");
T (abstract ~name:"a" ~size:12 ~alignment:4)];

T float,
[T int8_t; T uint16_t; T int; T short; T complex64;
T (bigarray array1 10 Bigarray.int32); T (array 5 int32_t);
T (bigarray array1 10 Bigarray_compat.int32); T (array 5 int32_t);
T (structure "s"); T (union "u");
T (abstract ~name:"a" ~size:12 ~alignment:4)];

T ldouble,
[T int8_t; T uint16_t; T int; T short; T complex64;
T (bigarray array1 10 Bigarray.int32); T (array 5 int32_t);
T (bigarray array1 10 Bigarray_compat.int32); T (array 5 int32_t);
T (structure "s"); T (union "u");
T (abstract ~name:"a" ~size:12 ~alignment:4)];

T short,
[T uint16_t; T float; T complex64; T (bigarray array1 10 Bigarray.int32);
[T uint16_t; T float; T complex64; T (bigarray array1 10 Bigarray_compat.int32);
T (array 5 int32_t); T (structure "s"); T (union "u");
T (abstract ~name:"a" ~size:12 ~alignment:4)];

T complex64,
[T int8_t; T uint16_t; T int; T float; T short;
T (bigarray array1 10 Bigarray.int32); T (array 5 int32_t);
T (bigarray array1 10 Bigarray_compat.int32); T (array 5 int32_t);
T (structure "s"); T (union "u");
T (abstract ~name:"a" ~size:12 ~alignment:4)];

T complexld,
[T int8_t; T uint16_t; T int; T short;
T (bigarray array1 10 Bigarray.int32); T (array 5 int32_t);
T (bigarray array1 10 Bigarray_compat.int32); T (array 5 int32_t);
T (structure "s"); T (union "u");
T (abstract ~name:"a" ~size:12 ~alignment:4)];

T (bigarray array1 10 Bigarray.int32),
T (bigarray array1 10 Bigarray_compat.int32),
[T int8_t; T uint16_t; T int; T float; T short; T complex64;
T (bigarray array1 10 Bigarray.int32); T (array 5 int32_t);
T (bigarray array1 10 Bigarray_compat.int32); T (array 5 int32_t);
T (structure "s"); T (union "u");
T (abstract ~name:"a" ~size:12 ~alignment:4)];

T (array 5 int32_t),
[T int8_t; T uint16_t; T int; T float; T short; T complex64;
T (bigarray array1 10 Bigarray.int32); T (array 5 int32_t);
T (bigarray array1 10 Bigarray_compat.int32); T (array 5 int32_t);
T (structure "s"); T (union "u");
T (abstract ~name:"a" ~size:12 ~alignment:4)];

T (structure "s"),
[T int8_t; T uint16_t; T int; T float; T short; T complex64;
T (bigarray array1 10 Bigarray.int32); T (array 5 int32_t);
T (bigarray array1 10 Bigarray_compat.int32); T (array 5 int32_t);
T (structure "s"); T (union "u");
T (abstract ~name:"a" ~size:12 ~alignment:4)];

T (union "u"),
[T int8_t; T uint16_t; T int; T float; T short; T complex64;
T (bigarray array1 10 Bigarray.int32); T (array 5 int32_t);
T (bigarray array1 10 Bigarray_compat.int32); T (array 5 int32_t);
T (structure "s"); T (union "u");
T (abstract ~name:"a" ~size:12 ~alignment:4)];

T (abstract ~name:"a" ~size:12 ~alignment:4),
[T int8_t; T uint16_t; T int; T float; T short; T complex64;
T (bigarray array1 10 Bigarray.int32); T (array 5 int32_t);
T (bigarray array1 10 Bigarray_compat.int32); T (array 5 int32_t);
T (structure "s"); T (union "u");
T (abstract ~name:"a" ~size:12 ~alignment:4)];

T ocaml_string,
[T int8_t; T uint16_t; T int; T float; T short; T complex64;
T (bigarray array1 10 Bigarray.int32); T (array 5 int32_t);
T (bigarray array1 10 Bigarray_compat.int32); T (array 5 int32_t);
T (structure "s"); T (union "u");
T (abstract ~name:"a" ~size:12 ~alignment:4)];
]
Expand Down
2 changes: 1 addition & 1 deletion tests/test-foreign_values/stubs/functions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct
(int @-> int @-> returning int))

let string_array = F.(foreign_value "string_array" (array 2 string))
let int_array = F.(foreign_value "int_array" (bigarray array1 5 Bigarray.int32))
let int_array = F.(foreign_value "int_array" (bigarray array1 5 Bigarray_compat.int32))
end


Expand Down
4 changes: 2 additions & 2 deletions tests/test-foreign_values/test_foreign_values.ml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ struct

let iarr = !@int_array in
begin
let expected_ints = Bigarray.(Array1.create int32 c_layout 5) in
let expected_ints = Bigarray_compat.(Array1.create int32 c_layout 5) in
for i = 0 to 4 do
Bigarray.Array1.set expected_ints i (Int32.of_int i)
Bigarray_compat.Array1.set expected_ints i (Int32.of_int i)
done;
assert_equal expected_ints iarr
end
Expand Down
2 changes: 1 addition & 1 deletion tests/test-lwt-jobs/test_lwt_jobs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ let test_sqrt _ =
*)
let test_object_lifetime _ =
let call =
let open Bigarray in
let open Bigarray_compat in
let b = Array1.create int32 c_layout 3 in
begin
b.{0} <- 1l;
Expand Down
2 changes: 1 addition & 1 deletion tests/test-lwt-preemptive/test_lwt_jobs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ let test_sqrt _ =
*)
let test_object_lifetime _ =
let call =
let open Bigarray in
let open Bigarray_compat in
let b = Array1.create int32 c_layout 3 in
begin
b.{0} <- 1l;
Expand Down
16 changes: 8 additions & 8 deletions tests/test-passable/test_passable.ml
Original file line number Diff line number Diff line change
Expand Up @@ -147,35 +147,35 @@ let test_arrays_are_not_passable _ =
let test_bigarrays_are_not_passable _ =
assert_raises ~msg:"bigarray type rejected as argument"
(Unsupported "Unsupported argument type")
(fun () -> bigarray genarray [|1|] Bigarray.int @-> returning void);
(fun () -> bigarray genarray [|1|] Bigarray_compat.int @-> returning void);

assert_raises ~msg:"bigarray1 type rejected as argument"
(Unsupported "Unsupported argument type")
(fun () -> bigarray array1 1 Bigarray.int @-> returning void);
(fun () -> bigarray array1 1 Bigarray_compat.int @-> returning void);

assert_raises ~msg:"bigarray2 type rejected as argument"
(Unsupported "Unsupported argument type")
(fun () -> bigarray array2 (1, 2) Bigarray.int @-> returning void);
(fun () -> bigarray array2 (1, 2) Bigarray_compat.int @-> returning void);

assert_raises ~msg:"bigarray3 type rejected as argument"
(Unsupported "Unsupported argument type")
(fun () -> bigarray array3 (1, 2, 3) Bigarray.int @-> returning void);
(fun () -> bigarray array3 (1, 2, 3) Bigarray_compat.int @-> returning void);

assert_raises ~msg:"bigarray type rejected as return type"
(Unsupported "Unsupported return type")
(fun () -> void @-> returning (bigarray genarray [|1|] Bigarray.int));
(fun () -> void @-> returning (bigarray genarray [|1|] Bigarray_compat.int));

assert_raises ~msg:"bigarray1 type rejected as return type"
(Unsupported "Unsupported return type")
(fun () -> void @-> returning (bigarray array1 1 Bigarray.int));
(fun () -> void @-> returning (bigarray array1 1 Bigarray_compat.int));

assert_raises ~msg:"bigarray2 type rejected as return type"
(Unsupported "Unsupported return type")
(fun () -> void @-> returning (bigarray array2 (1, 2) Bigarray.int));
(fun () -> void @-> returning (bigarray array2 (1, 2) Bigarray_compat.int));

assert_raises ~msg:"bigarray3 type rejected as return type"
(Unsupported "Unsupported return type")
(fun () -> void @-> returning (bigarray array3 (1, 2, 3) Bigarray.int))
(fun () -> void @-> returning (bigarray array3 (1, 2, 3) Bigarray_compat.int))


(*
Expand Down
4 changes: 2 additions & 2 deletions tests/test-sizeof/test_sizeof.ml
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ end
*)
let test_sizeof_bigarrays _ =
let module M = struct
module B = Bigarray
type k = K : ('a, 'b) Bigarray.kind * int -> k
module B = Bigarray_compat
type k = K : ('a, 'b) Bigarray_compat.kind * int -> k
let kind_sizes = [
K (B.float32, 4);
K (B.float64, 8);
Expand Down
24 changes: 12 additions & 12 deletions tests/test-type_printing/test_type_printing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -434,22 +434,22 @@ let test_ocaml_string_printing _ =
let test_bigarray_signed_printing _ =
begin
assert_typ_printed_as "int8_t[1][3]"
(bigarray genarray [|1; 3|] Bigarray.int8_signed);
(bigarray genarray [|1; 3|] Bigarray_compat.int8_signed);

assert_typ_printed_as "int16_t[3]"
(bigarray array1 3 Bigarray.int16_signed);
(bigarray array1 3 Bigarray_compat.int16_signed);

assert_typ_printed_as "int32_t[5][6]"
(bigarray array2 (5, 6) Bigarray.int32);
(bigarray array2 (5, 6) Bigarray_compat.int32);

assert_typ_printed_as "int64_t[7][8]"
(bigarray array2 (7, 8) Bigarray.int64);
(bigarray array2 (7, 8) Bigarray_compat.int64);

assert_typ_printed_as "intnat[9][10]"
(bigarray array2 (9, 10) Bigarray.int);
(bigarray array2 (9, 10) Bigarray_compat.int);

assert_typ_printed_as "intnat[13][14][15]"
(bigarray array3 (13, 14, 15) Bigarray.nativeint);
(bigarray array3 (13, 14, 15) Bigarray_compat.nativeint);
end


Expand All @@ -461,10 +461,10 @@ let test_bigarray_unsigned_printing _ =
"Unsigned bigarray elements currently indistinguishable from signed elements";
begin
assert_typ_printed_as "uint8_t[2]"
(bigarray array1 2 Bigarray.int8_unsigned);
(bigarray array1 2 Bigarray_compat.int8_unsigned);

assert_typ_printed_as "uint16_t[4]"
(bigarray array1 4 Bigarray.int16_unsigned);
(bigarray array1 4 Bigarray_compat.int16_unsigned);
end


Expand All @@ -474,16 +474,16 @@ let test_bigarray_unsigned_printing _ =
let test_bigarray_float_printing _ =
begin
assert_typ_printed_as "float[10][100]"
(bigarray genarray [|10; 100|] Bigarray.float32);
(bigarray genarray [|10; 100|] Bigarray_compat.float32);

assert_typ_printed_as "double[20][30][40]"
(bigarray genarray [|20; 30; 40|] Bigarray.float64);
(bigarray genarray [|20; 30; 40|] Bigarray_compat.float64);

assert_typ_printed_as "float _Complex[16][17][18]"
(bigarray array3 (16, 17, 18) Bigarray.complex32);
(bigarray array3 (16, 17, 18) Bigarray_compat.complex32);

assert_typ_printed_as "double _Complex[19][20][21]"
(bigarray array3 (19, 20, 21) Bigarray.complex64);
(bigarray array3 (19, 20, 21) Bigarray_compat.complex64);
end


Expand Down

0 comments on commit aeade51

Please sign in to comment.