Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Fix some more tests #1811

Merged
merged 2 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* Runtime: no longer leak channels
* Runtime: Fix Marshal.to_buffer (#1798)
* Runtime: unmarshalling objects should refresh its id
* Runtime: check size upper bound during array creation

# 5.9.1 (02-12-2024) - Lille

Expand Down
10 changes: 4 additions & 6 deletions compiler/tests-ocaml/lib-floatarray/floatarray.ml
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ module Test (A : S) : sig end = struct
check_inval (fun i -> A.set a i 1.0) (-1);
check_inval (fun i -> A.set a i 1.0) 1000;
check_inval A.create (-1);
(* check_inval A.create (A.max_length + 1);*)
check_inval A.create (A.max_length + 1);
check_inval (fun i -> A.make i 1.0) (-1);
(* check_inval (fun i -> A.make i 1.0) (A.max_length + 1); *)
check_inval (fun i -> A.make i 1.0) (A.max_length + 1);

(* [length] *)
let test_length l = assert (l = (A.length (A.create l))) in
Expand All @@ -125,8 +125,7 @@ module Test (A : S) : sig end = struct
let a = A.init 1000 Float.of_int in
check_i a;
check_inval (fun i -> A.init i Float.of_int) (-1);
(* check_inval (fun i -> A.init i Float.of_int) (A.max_length + 1); *)

check_inval (fun i -> A.init i Float.of_int) (A.max_length + 1);

(* [make_matrix] *)
let check_make_matrix m n =
Expand Down Expand Up @@ -641,8 +640,7 @@ module Test (A : S) : sig end = struct
assert (compare value value' = 0)
in
let l = [0.; 0.25; -4.; 3.14159265; nan; infinity; neg_infinity; neg_zero] in
(* js_of_ocaml doesn't marshal floats *)
if false then test_structured_io (A.of_list l);
test_structured_io (A.of_list l);

(* map_inplace *)
let a = A.init 4 (fun i -> Float.of_int (i + 1)) in
Expand Down
10 changes: 5 additions & 5 deletions compiler/tests-ocaml/lib-hashtbl/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
(deps ../../../LICENSE)
(modules hfun)
(libraries)
(modes js))
(modes wasm))

(tests
(names hfun_wasm)
(names hfun_js)
(deps ../../../LICENSE)
(modules hfun_wasm)
(modules hfun_js)
(libraries)
(modes wasm))
(modes js))

(rule
(copy hfun.ml hfun_wasm.ml))
(copy hfun.ml hfun_js.ml))

(tests
(names htbl)
Expand Down
12 changes: 6 additions & 6 deletions compiler/tests-ocaml/lib-hashtbl/hfun.expected
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
2^30-1 23c392d0
-2^30 0c66fde3
-- Floats:
+0.0 07be548a
-0.0 07be548a
+0.0 0f478b8c
-0.0 0f478b8c
+infty 23ea56fb
-infty 059f7872
NaN 3228858d
NaN#2 3228858d
NaN#3 3228858d
-- Native integers:
0 07be548a
0 3f19274a
-1 3653e015
42 1792870b
2^30-1 23c392d0
-2^30 0c66fde3
42 3e33aef8
2^30-1 3711bf46
-2^30 2e71f39c
-- Lists:
[0..10] 0ade0fc9
[0..12] 0ade0fc9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
2^30-1 23c392d0
-2^30 0c66fde3
-- Floats:
+0.0 0f478b8c
-0.0 0f478b8c
+0.0 07be548a
-0.0 07be548a
+infty 23ea56fb
-infty 059f7872
NaN 3228858d
NaN#2 3228858d
NaN#3 3228858d
-- Native integers:
0 3f19274a
0 07be548a
-1 3653e015
42 3e33aef8
2^30-1 3711bf46
-2^30 2e71f39c
42 1792870b
2^30-1 23c392d0
-2^30 0c66fde3
-- Lists:
[0..10] 0ade0fc9
[0..12] 0ade0fc9
Expand Down
21 changes: 13 additions & 8 deletions runtime/js/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function caml_check_bound(array, index) {
//Provides: caml_array_make const (const, mutable)
//Requires: caml_array_bound_error
function caml_array_make(len, init) {
if (len < 0) caml_array_bound_error();
if (len >>> 0 >= ((0x7fffffff / 4) | 0)) caml_array_bound_error();
var len = (len + 1) | 0;
var b = new Array(len);
b[0] = 0;
Expand All @@ -175,7 +175,7 @@ function caml_make_vect(len, init) {
//Provides: caml_make_float_vect const (const)
//Requires: caml_array_bound_error
function caml_make_float_vect(len) {
if (len < 0) caml_array_bound_error();
if (len >>> 0 >= ((0x7fffffff / 8) | 0)) caml_array_bound_error();
var len = (len + 1) | 0;
var b = new Array(len);
b[0] = 254;
Expand All @@ -187,7 +187,7 @@ function caml_make_float_vect(len) {
//Requires: caml_array_bound_error
//Version: >= 5.3
function caml_array_create_float(len) {
if (len < 0) caml_array_bound_error();
if (len >>> 0 >= ((0x7fffffff / 8) | 0)) caml_array_bound_error();
var len = (len + 1) | 0;
var b = new Array(len);
b[0] = 254;
Expand All @@ -197,7 +197,7 @@ function caml_array_create_float(len) {
//Provides: caml_floatarray_create const (const)
//Requires: caml_array_bound_error
function caml_floatarray_create(len) {
if (len < 0) caml_array_bound_error();
if (len >>> 0 >= ((0x7fffffff / 8) | 0)) caml_array_bound_error();
var len = (len + 1) | 0;
var b = new Array(len);
b[0] = 254;
Expand All @@ -206,17 +206,22 @@ function caml_floatarray_create(len) {
}

//Provides: caml_floatarray_make const (const)
//Requires: caml_array_make
//Requires: caml_array_bound_error
//Version: >= 5.3
function caml_floatarray_make(len, init) {
return caml_array_make(len, init);
if (len >>> 0 >= ((0x7fffffff / 8) | 0)) caml_array_bound_error();
var len = (len + 1) | 0;
var b = new Array(len);
b[0] = 254;
for (var i = 1; i < len; i++) b[i] = init;
return b;
}

//Provides: caml_floatarray_make_unboxed const (const)
//Requires: caml_array_make
//Requires: caml_floatarray_make
//Version: >= 5.3
function caml_floatarray_make_unboxed(len, init) {
return caml_array_make(len, init);
return caml_floatarray_make(len, init);
}

//Provides: caml_uniform_array_make const (const)
Expand Down
6 changes: 3 additions & 3 deletions runtime/wasm/array.wat
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
(param $n (ref eq)) (param $v (ref eq)) (result (ref eq))
(local $sz i32) (local $b (ref $block)) (local $f f64)
(local.set $sz (i31.get_s (ref.cast (ref i31) (local.get $n))))
(if (i32.lt_s (local.get $sz) (i32.const 0))
(if (i32.ge_u (local.get $sz) (i32.const 0xfffffff))
(then
(call $caml_invalid_argument
(array.new_data $string $Array_make
Expand All @@ -55,7 +55,7 @@
(param $n (ref eq)) (param $v (ref eq)) (result (ref eq))
(local $sz i32) (local $f f64)
(local.set $sz (i31.get_s (ref.cast (ref i31) (local.get $n))))
(if (i32.lt_s (local.get $sz) (i32.const 0))
(if (i32.ge_u (local.get $sz) (i32.const 0x7ffffff))
(then
(call $caml_invalid_argument
(array.new_data $string $Array_make
Expand All @@ -72,7 +72,7 @@
(param $n (ref eq)) (result (ref eq))
(local $sz i32)
(local.set $sz (i31.get_s (ref.cast (ref i31) (local.get $n))))
(if (i32.lt_s (local.get $sz) (i32.const 0))
(if (i32.ge_u (local.get $sz) (i32.const 0x7ffffff))
(then
(call $caml_invalid_argument
(array.new_data $string $Array_make
Expand Down
Loading