Skip to content

Commit

Permalink
CI: run some Jane Street tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vouillon committed Nov 27, 2023
1 parent d67c215 commit 931ded6
Show file tree
Hide file tree
Showing 2 changed files with 312 additions and 55 deletions.
104 changes: 49 additions & 55 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,42 +109,30 @@ jobs:
/opt/hostedtoolcache/opam/2.1.5/x86_64/opam
key: ${{ runner.os }}-ocaml-${{ matrix.ocaml-compiler }}

- name: Checkout code
uses: actions/checkout@v4
with:
path: wasm_of_ocaml

- name: Checkout Jane Street opam repository
uses: actions/checkout@v4
with:
repository: janestreet/opam-repository
path: jane-street/opam-repository

- name: Pin dune
run: |
opam pin add -n dune.3.11 https://github.com/ocaml-wasm/dune.git#wasm
- name: Pin packages
run: |
opam pin add -n alcotest https://github.com/ocaml-wasm/alcotest.git#wasm
opam pin add -n async_js https://github.com/ocaml-wasm/async_js.git#wasm
opam pin add -n base https://github.com/ocaml-wasm/base.git#wasm
opam pin add -n base_bigstring https://github.com/ocaml-wasm/base_bigstring.git#wasm
opam pin add -n bigstringaf https://github.com/ocaml-wasm/bigstringaf.git#wasm
opam pin add -n bin_prot https://github.com/ocaml-wasm/bin_prot.git#wasm
opam pin add -n bonsai https://github.com/ocaml-wasm/bonsai.git#wasm
opam pin add -n brr https://github.com/ocaml-wasm/brr.git#wasm
opam pin add -n core https://github.com/ocaml-wasm/core.git#wasm
opam pin add -n core_kernel https://github.com/ocaml-wasm/core_kernel.git#wasm
opam pin add -n cstruct https://github.com/ocaml-wasm/ocaml-cstruct.git#wasm
opam pin add -n gen_js_api https://github.com/ocaml-wasm/gen_js_api.git#wasm
opam pin add -n incr_dom https://github.com/ocaml-wasm/incr_dom.git#wasm
opam pin add -n js_of_ocaml_patches https://github.com/ocaml-wasm/js_of_ocaml_patches.git#wasm
opam pin add -n ppx_css https://github.com/ocaml-wasm/ppx_css.git#wasm
opam pin add -n ppx_expect https://github.com/ocaml-wasm/ppx_expect.git#wasm
opam pin add -n ppx_inline_test https://github.com/ocaml-wasm/ppx_inline_test.git#wasm
opam pin add -n string_dict https://github.com/ocaml-wasm/string_dict.git#wasm
opam pin add -n time_now https://github.com/ocaml-wasm/time_now.git#wasm
opam pin add -n virtual_dom https://github.com/ocaml-wasm/virtual_dom.git#wasm
opam pin add -n zarith_stubs_js https://github.com/ocaml-wasm/zarith_stubs_js.git#wasm
- name: Install opam file parser
run: opam install opam-format ocamlfind

- name: Checkout Jane Street packages
run: opam exec -- ocaml wasm_of_ocaml/tools/ci_setup.ml

- name: Update dune and test dependencies
run: opam install dune num cohttp-lwt-unix graphics ppx_expect zarith.1.12

- name: Checkout code
uses: actions/checkout@v4
with:
path: wasm_of_ocaml

- name: Build wasm_of_ocaml
working-directory: ./wasm_of_ocaml
run: |
Expand All @@ -160,41 +148,47 @@ jobs:
working-directory: ./wasm_of_ocaml
run: opam exec -- dune build @all @runtest --profile wasm-effects

- name: Install bonsai and zarith_stubs_js
- name: Run Base tests
if: ${{ matrix.ocaml-compiler < '5.' }}
run: opam install dune bonsai zarith_stubs_js
working-directory: ./jane-street/lib/base
run: opam exec -- dune runtest

- name: Checkout zarith_stubs_js
- name: Run Base bigstring tests
if: ${{ matrix.ocaml-compiler < '5.' }}
uses: actions/checkout@v4
with:
repository: ocaml-wasm/zarith_stubs_js
path: zarith
ref: wasm
working-directory: ./jane-street/lib/base_bigstring
run: opam exec -- dune runtest

- name: Run zarith_stubs_js tests
- name: Run Core tests
if: ${{ matrix.ocaml-compiler < '5.' }}
working-directory: ./zarith
run: |
opam exec -- dune build @runtest --profile wasm
working-directory: ./jane-street/lib/core
run: opam exec -- dune runtest

- name: Checkout bonsai
- name: Run Bignum tests
if: ${{ matrix.ocaml-compiler < '5.' }}
uses: actions/checkout@v4
with:
repository: ocaml-wasm/bonsai
path: bonsai
ref: wasm
working-directory: ./jane-street/lib/bignum
run: opam exec -- dune runtest

- name: Install bonsai dependencies
- name: Run Bin_prot tests
if: ${{ matrix.ocaml-compiler < '5.' }}
working-directory: ./bonsai
run: |
sudo apt-get install libgraph-easy-perl
npm install deasync
working-directory: ./jane-street/lib/bin_prot
run: opam exec -- dune runtest

- name: Run bonsai tests
- name: Run String_dict tests
if: ${{ matrix.ocaml-compiler < '5.' }}
working-directory: ./bonsai
run: |
opam exec -- dune build @runtest --profile wasm
working-directory: ./jane-street/lib/string_dict
run: opam exec -- dune runtest

- name: Run Zarith tests
if: ${{ matrix.ocaml-compiler < '5.' }}
working-directory: ./jane-street/lib/zarith_stubs_js
run: opam exec -- dune runtest

- name: Run Virtual_dom tests
if: ${{ matrix.ocaml-compiler < '5.' }}
working-directory: ./jane-street/lib/virtual_dom
run: opam exec -- dune runtest

- name: Run Bonsai tests
if: ${{ matrix.ocaml-compiler < '5.' }}
working-directory: ./jane-street/lib/bonsai
run: opam exec -- dune runtest
263 changes: 263 additions & 0 deletions tools/ci_setup.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
#use "topfind"

#require "opam-format"

#require "unix"

#require "str"

module StringSet = Set.Make (String)

(****)

let repo = "jane-street/opam-repository/packages"

let roots = [ "bonsai"; "string_dict" ]

let omitted_others = StringSet.of_list [ "cohttp-async"; "cohttp"; "uri"; "uri-sexp" ]

let omitted_js = StringSet.of_list [ "sexplib0" ]

let do_not_pin = StringSet.of_list [ "wasocaml"; "wasm_of_ocaml" ]

let do_pin = StringSet.of_list [ "base"; "ppx_expect"; "ppx_inline_test"; "time_now" ]

let aliases = [ "ocaml-cstruct", "cstruct" ]

let dune_workspace =
{|(lang dune 3.11)
(env
(_
(env-vars (TESTING_FRAMEWORK inline-test))
(js_of_ocaml (target wasm))
(flags :standard -warn-error -8-32-34-49-52-55 -w -67-69)))
|}

let patches =
[ ( "sexp_grammar"
, {|
diff --git a/sexp_grammar_validation.opam b/sexp_grammar_validation.opam
new file mode 100644
index 0000000..e69de29
diff --git a/validation/src/dune b/validation/src/dune
index 5c51676..b371eaa 100644
--- a/validation/src/dune
+++ b/validation/src/dune
@@ -1,4 +1,5 @@
(library (name sexp_grammar_validation)
+ (public_name sexp_grammar_validation)
(libraries bignum.bigint core
expect_test_helpers_core.expect_test_helpers_base sexp_grammar)
(preprocess (pps ppx_jane)))
\ No newline at end of file
|}
)
; ( "bignum"
, {bignum|
diff --git a/test/src/dune b/test/src/dune
index 89ab13d..12133a8 100644
--- a/test/src/dune
+++ b/test/src/dune
@@ -1,4 +1,5 @@
(library (name bignum_test)
(libraries bigint bignum core expect_test_helpers_core
sexp_grammar_validation)
- (preprocess (pps ppx_jane)))
\ No newline at end of file
+ (inline_tests (flags -drop-tag no-js -drop-tag no-wasm -drop-tag 64-bits-only) (modes js))
+ (preprocess (pps ppx_jane)))
diff --git a/test/src/test_bignum.ml b/test/src/test_bignum.ml
index 47ca701..a096d6c 100644
--- a/test/src/test_bignum.ml
+++ b/test/src/test_bignum.ml
@@ -3,6 +3,11 @@ open! Expect_test_helpers_core
open Bignum
open Bignum.For_testing

+module Zarith = struct
+ module Q = Q
+ module Z = Z
+end
+
let%test_unit "Bignum.(//)" =
let open Bignum.O in
for i = -4 to 4 do
@@ -62,7 +67,7 @@ let%expect_test "Bignum.sexp_of_t does use Scientific Notation" =
let compare_floats ~of_float x =
let x' = x |> of_float |> Bignum.to_float in
if not (Float.( = ) x x' || (Float.is_nan x && Float.is_nan x'))
- then raise_s [%message "mismatch" (x : float) (x' : float)]
+ then raise_s [%message "mismatch" (x : float) (x' : float) (x |> of_float : Bignum.t)]
;;

let%expect_test "roundtrip: f |> Bignum.of_float_decimal |> Bignum.to_float" =
@@ -774,7 +779,7 @@ let%test_module _ =
-1073741825 -> ( 6) \001\253\255\255\255\191 |}]
;;

- let%expect_test ("bin_io serialization V2 (javascript)" [@tags "js-only"]) =
+ let%expect_test ("bin_io serialization V2 (javascript)" [@tags "js-only", "no-wasm"]) =
bin_io_tests (module V2);
[%expect
{|
@@ -802,6 +807,34 @@ let%test_module _ =
-1073741825 -> ( 6) \001\253\255\255\255\191 |}]
;;

+ let%expect_test ("bin_io serialization V2 (Wasm)" [@tags "wasm-only"]) =
+ bin_io_tests (module V2);
+ [%expect
+ {|
+ 0 -> ( 1) \000
+ 1 -> ( 2) \001\001
+ -1 -> ( 3) \001\255\255
+ 100000001 -> ( 6) \001\253\001\225\245\005
+ 1000000.1 -> ( 6) \002\253\129\150\152\000
+ 100000.01 -> ( 6) \003\253\129\150\152\000
+ 10000.001 -> ( 6) \004\253\129\150\152\000
+ 1000.0001 -> ( 6) \005\253\129\150\152\000
+ 100.00001 -> ( 6) \006\253\129\150\152\000
+ 10.000001 -> ( 6) \007\253\129\150\152\000
+ 1.0000001 -> ( 6) \008\253\129\150\152\000
+ 0.10000001 -> ( 6) \009\253\129\150\152\000
+ 0.010000001 -> (11) \010\253\129\150\152\000\253\000\202\154\059
+ 0.0010000001 -> (22) \011\02010000001\04710000000000
+ 10000000000000 -> (16) \011\01410000000000000
+ -10000000000000 -> (17) \011\015\04510000000000000
+12345678901234567.12345678901234567 -> (55) \01151234567890123456712345678901234567\047100000000000000000
+ 1099511627775 -> (15) \011\0131099511627775
+ 1073741823 -> ( 6) \001\253\255\255\255\063
+ -1073741824 -> ( 6) \001\253\000\000\000\192
+ 1073741824 -> (12) \011\0101073741824
+ -1073741825 -> (13) \011\011\0451073741825 |}]
+ ;;
+
let%expect_test "bin_io de-serialization V2" =
(* Some bignums will have two bin_io representation depending on where their
were serialized. Make sure we're able to parse things back regardless of the
|bignum}
)
]
(****)
let read_opam_file filename =
OpamPp.parse
OpamPp.Op.(OpamFormat.I.file -| OpamPp.map_snd OpamFile.OPAM.pp_raw_fields)
~pos:{ filename; start = 0, 0; stop = 0, 0 }
(OpamParser.FullPos.file (Filename.concat (Filename.concat repo filename) "opam"))
let dependencies (_, { OpamFile.OPAM.depends }) =
let open OpamFormula in
depends
|> map (fun (nm, _) -> Atom (nm, None))
|> of_atom_formula
|> atoms
|> List.map fst
|> List.map OpamPackage.Name.to_string
let packages =
repo
|> Sys.readdir
|> Array.to_list
|> List.map (fun s -> String.sub s 0 (String.index s '.'), read_opam_file s)
let rec traverse visited p =
if StringSet.mem p visited
then visited
else
let visited = StringSet.add p visited in
match List.assoc p packages with
| exception Not_found -> visited
| opam ->
let l = dependencies opam in
List.fold_left traverse visited l
let forked_packages =
let ch =
Unix.open_process_in
"curl -L -H 'Accept: application/vnd.github+json' -H 'X-GitHub-Api-Version: \
2022-11-28' https://api.github.com/orgs/ocaml-wasm/repos 2> /dev/null | jq -r \
'.[] | .name'"
in
let l = Str.(split (regexp "\n")) (In_channel.input_all ch) in
close_in ch;
StringSet.of_list l
let is_forked p = StringSet.mem p forked_packages
let exec_async ~delay cmd =
let p =
Unix.open_process_out (Printf.sprintf "sleep %f; %s" (float delay /. 10.) cmd)
in
fun () -> ignore (Unix.close_process_out p)
let sync_exec f l =
let l = List.mapi f l in
List.iter (fun f -> f ()) l
let pin delay nm =
exec_async
~delay
(Printf.sprintf
"opam pin add -n %s https://github.com/ocaml-wasm/%s.git#wasm"
(try List.assoc nm aliases with Not_found -> nm)
nm)
let pin_packages js =
sync_exec
pin
(StringSet.elements
(StringSet.union
(StringSet.diff (StringSet.diff forked_packages js) do_not_pin)
do_pin))
let install_others others =
let others = StringSet.elements (StringSet.diff others omitted_others) in
ignore (Sys.command ("opam install -y " ^ String.concat " " others))
let clone delay ?branch nm src =
exec_async
~delay
(Printf.sprintf
"git clone -q --depth 1 %s%s jane-street/lib/%s"
(match branch with
| None -> ""
| Some b -> Printf.sprintf "-b %s " b)
src
nm)
let () =
Out_channel.(
with_open_bin "jane-street/dune-workspace"
@@ fun ch -> output_string ch dune_workspace)
let () =
let js, others =
List.fold_left traverse StringSet.empty roots
|> StringSet.partition (fun p -> List.mem_assoc p packages)
in
pin_packages js;
install_others others;
sync_exec (fun i () -> clone i "ocaml-uri" "https://github.com/mirage/ocaml-uri") [ () ];
sync_exec
(fun i nm ->
clone
i
?branch:(if is_forked nm then Some "wasm" else None)
nm
(Printf.sprintf
"https://github.com/%s/%s"
(if is_forked nm then "ocaml-wasm" else "janestreet")
nm))
(StringSet.elements (StringSet.diff js omitted_js))
let () =
List.iter
(fun (dir, patch) ->
let ch =
Unix.open_process_out (Printf.sprintf "cd jane-street/lib/%s && patch -p 1" dir)
in
output_string ch patch;
ignore (Unix.close_process_out ch))
patches

0 comments on commit 931ded6

Please sign in to comment.