Skip to content

Commit

Permalink
wip: repair tests
Browse files Browse the repository at this point in the history
  • Loading branch information
c-cube committed Sep 10, 2023
1 parent 858885c commit 6a76080
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 162 deletions.
2 changes: 1 addition & 1 deletion src/tests/benchmark/benchmark_single_ml.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module type T_sig = Ocaml_test_runner.T_sig

module Bench_t = Benchmark_types
module Bench_t = Benchmark

module Util = struct
let shuffle_array a n =
Expand Down
7 changes: 3 additions & 4 deletions src/tests/benchmark/dune
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
(rule
(targets benchmark_types.ml benchmark_pb.ml benchmark_pp.ml
benchmark_types.mli benchmark_pb.mli benchmark_pp.mli)
(targets benchmark.ml benchmark.mli)
(deps benchmark.proto)
(action
(run ocaml-protoc -binary -pp -ml_out ./ %{deps})))
(run ocaml-protoc --binary --pp --ml_out ./ %{deps})))

(executable
(name benchmark_single_ml)
(modules benchmark_single_ml ocaml_test_types ocaml_test_runner
benchmark_types benchmark_pb benchmark_pp)
benchmark)
(libraries pbrt unix))
18 changes: 9 additions & 9 deletions src/tests/benchmark/ocaml_test_runner.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ end
(* T_sig *)

module type Runner_sig = sig
val run : Benchmark_types.test_request -> Benchmark_types.test_response
val run : Benchmark.test_request -> Benchmark.test_response
(** [run request] execute the corresponding request and returns
the test response
*)
end

module Make (T : T_sig) : Runner_sig = struct
let run { Benchmark_types.type_; file_name; test_id } =
let run { Benchmark.type_; file_name; test_id } =
match type_ with
| Benchmark_types.Encode difficulty ->
| Benchmark.Encode difficulty ->
let t0 = Unix.gettimeofday () in

let encoder = Pbrt.Encoder.create () in
Expand All @@ -45,16 +45,16 @@ module Make (T : T_sig) : Runner_sig = struct
let t3 = Unix.gettimeofday () in

let encode_data =
Benchmark_types.
Benchmark.
{
creation_time = t1 -. t0;
encode_time = t2 -. t1;
to_file_time = t3 -. t2;
}
in

Benchmark_types.{ difficulty_size; test_id; data = Encode encode_data }
| Benchmark_types.Decode ->
Benchmark.{ difficulty_size; test_id; data = Encode encode_data }
| Benchmark.Decode ->
let t0 = Unix.gettimeofday () in
let ic = open_in file_name in
let len = in_channel_length ic in
Expand All @@ -64,15 +64,15 @@ module Make (T : T_sig) : Runner_sig = struct
let t1 = Unix.gettimeofday () in
let v = T.decode (Pbrt.Decoder.of_bytes payload) in
let t2 = Unix.gettimeofday () in
Benchmark_types.
Benchmark.
{
difficulty_size = T.difficulty_size v;
test_id;
data =
Decode
{
Benchmark_types.from_file_time = t1 -. t0;
Benchmark_types.decode_time = t2 -. t1;
Benchmark.from_file_time = t1 -. t0;
Benchmark.decode_time = t2 -. t1;
};
}
end
Expand Down
2 changes: 1 addition & 1 deletion src/tests/benchmark/ocaml_test_runner.mli
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ end
(* T_sig *)

module type Runner_sig = sig
val run : Benchmark_types.test_request -> Benchmark_types.test_response
val run : Benchmark.test_request -> Benchmark.test_response
(** [run request] execute the corresponding request and returns
the test response
*)
Expand Down
52 changes: 24 additions & 28 deletions src/tests/benchmark/ocaml_test_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,40 @@ let difficulty_size_of_difficulty = function
| _ -> failwith "Invalid difficulty"

module Int32List = struct
type t = Benchmark_types.int32_list
type t = Benchmark.int32_list

let rec make_impl acc = function
| 0l -> acc
| n -> make_impl (n :: acc) (Int32.sub n 1l)

let make difficulty =
let difficulty_size = difficulty_size_of_difficulty difficulty in
( Benchmark_types.
{ int32_list = make_impl [] (Int32.of_int difficulty_size) },
( Benchmark.{ int32_list = make_impl [] (Int32.of_int difficulty_size) },
difficulty_size )

let difficulty_size { Benchmark_types.int32_list } = List.length int32_list
let encode = Benchmark_pb.encode_int32_list
let decode = Benchmark_pb.decode_int32_list
let difficulty_size { Benchmark.int32_list } = List.length int32_list
let encode = Benchmark.encode_pb_int32_list
let decode = Benchmark.decode_pb_int32_list
end

module IntList = struct
type t = Benchmark_types.int_list
type t = Benchmark.int_list

let rec make_impl acc = function
| 0 -> acc
| n -> make_impl (n :: acc) (n - 1)

let make difficulty =
let difficulty_size = difficulty_size_of_difficulty difficulty in
Benchmark_types.{ int_list = make_impl [] difficulty_size }, difficulty_size
Benchmark.{ int_list = make_impl [] difficulty_size }, difficulty_size

let difficulty_size { Benchmark_types.int_list } = List.length int_list
let encode = Benchmark_pb.encode_int_list
let decode = Benchmark_pb.decode_int_list
let difficulty_size { Benchmark.int_list } = List.length int_list
let encode = Benchmark.encode_pb_int_list
let decode = Benchmark.decode_pb_int_list
end

module IntRepeated = struct
type t = Benchmark_types.int_repeated
type t = Benchmark.int_repeated

let make_impl n =
let r = Pbrt.Repeated_field.make 0 in
Expand All @@ -57,18 +56,17 @@ module IntRepeated = struct

let make difficulty =
let difficulty_size = difficulty_size_of_difficulty difficulty in
( Benchmark_types.{ int_repeated = make_impl difficulty_size },
difficulty_size )
Benchmark.{ int_repeated = make_impl difficulty_size }, difficulty_size

let difficulty_size { Benchmark_types.int_repeated } =
let difficulty_size { Benchmark.int_repeated } =
Pbrt.Repeated_field.length int_repeated

let encode = Benchmark_pb.encode_int_repeated
let decode = Benchmark_pb.decode_int_repeated
let encode = Benchmark.encode_pb_int_repeated
let decode = Benchmark.decode_pb_int_repeated
end

module IntPackedRepeated = struct
type t = Benchmark_types.int_packed_repeated
type t = Benchmark.int_packed_repeated

let make_impl n =
let r = Pbrt.Repeated_field.make 0 in
Expand All @@ -82,20 +80,18 @@ module IntPackedRepeated = struct

let make difficulty =
let difficulty_size = difficulty_size_of_difficulty difficulty in
let v =
Benchmark_types.{ int_packed_repeated = make_impl difficulty_size }
in
let v = Benchmark.{ int_packed_repeated = make_impl difficulty_size } in
v, difficulty_size

let difficulty_size { Benchmark_types.int_packed_repeated = l } =
let difficulty_size { Benchmark.int_packed_repeated = l } =
Pbrt.Repeated_field.length l

let encode = Benchmark_pb.encode_int_packed_repeated
let decode = Benchmark_pb.decode_int_packed_repeated
let encode = Benchmark.encode_pb_int_packed_repeated
let decode = Benchmark.decode_pb_int_packed_repeated
end

let get_test = function
| Benchmark_types.Int_list -> (module IntList : T_sig)
| Benchmark_types.Int_repeated -> (module IntRepeated : T_sig)
| Benchmark_types.Int_packed_repeated -> (module IntPackedRepeated : T_sig)
| Benchmark_types.Int32_list -> (module Int32List : T_sig)
| Benchmark.Int_list -> (module IntList : T_sig)
| Benchmark.Int_repeated -> (module IntRepeated : T_sig)
| Benchmark.Int_packed_repeated -> (module IntPackedRepeated : T_sig)
| Benchmark.Int32_list -> (module Int32List : T_sig)
2 changes: 1 addition & 1 deletion src/tests/benchmark/ocaml_test_types.mli
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(** Test type implementation *)

val get_test : Benchmark_types.test_id -> (module Ocaml_test_runner.T_sig)
val get_test : Benchmark.test_id -> (module Ocaml_test_runner.T_sig)
(** [get_test test_id] returns the module for the given [test_id] which
can then be plugged into the Ocaml_test_runner.Make functor
*)
8 changes: 4 additions & 4 deletions src/tests/google_unittest/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
(libraries pbrt))

(rule
(targets unittest_types.ml unittest_types.mli)
(targets unittest.ml unittest.mli)
(deps (:file unittest.proto) unittest_import.proto)
(action (run ocaml-protoc -ml_out . -I . %{file})))
(action (run ocaml-protoc --ml_out . -I . %{file})))

(rule
(targets unittest_import_types.ml unittest_import_types.mli)
(targets unittest_import.ml unittest_import.mli)
(deps (:file unittest_import.proto))
(action (run ocaml-protoc -ml_out . -I . %{file})))
(action (run ocaml-protoc --ml_out . -I . %{file})))

2 changes: 1 addition & 1 deletion src/tests/google_unittest/google_unittest.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module T = Unittest_types
module T = Unittest

let () =
assert (
Expand Down
Loading

0 comments on commit 6a76080

Please sign in to comment.