Skip to content

Commit 2e36f5d

Browse files
authoredJun 7, 2024··
Merge pull request #243 from mransan/simon/fix-integration-tests
fix integration tests
2 parents 13f9559 + 274fc93 commit 2e36f5d

38 files changed

+447
-94
lines changed
 

‎.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
_opam
2+
_build

‎.github/workflows/main.yml

+25-3
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ jobs:
2121
runs-on: ${{ matrix.os }}
2222
steps:
2323
- uses: actions/checkout@v2
24-
#with:
25-
# submodules: true
24+
with:
25+
submodules: true
2626
- uses: ocaml/setup-ocaml@v2
2727
with:
2828
ocaml-compiler: ${{ matrix.ocaml-compiler }}
@@ -34,7 +34,29 @@ jobs:
3434
- run: opam install -t . --deps-only
3535
- run: opam exec -- dune build @install
3636
- run: opam exec -- dune runtest
37-
#- run: opam exec -- make integration
37+
38+
integration:
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: actions/checkout@v2
42+
with:
43+
submodules: true
44+
- run: docker build -f dep/Dockerfile . --target=base
45+
- run: docker build -f dep/Dockerfile . --target=run-the-damn-build
46+
47+
format:
48+
name: format
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v2
52+
#with:
53+
# submodules: true
54+
- uses: ocaml/setup-ocaml@v2
55+
with:
56+
ocaml-compiler: 5.1
57+
allow-prerelease-opam: true
58+
dune-cache: true
59+
#- run: sudo apt install protobuf-compiler libprotobuf-dev
3860
- run: opam install ocamlformat.0.24.1
3961
- run: opam exec -- dune build @fmt --auto-promote
4062
- run: git diff -q

‎Makefile.test

+13-10
Original file line numberDiff line numberDiff line change
@@ -32,39 +32,42 @@ tests:
3232

3333
# location of where the Google protoc compiler is installed
3434
PB_INSTALL ?= /usr/
35-
PB_HINC = $(PB_INSTALL)/include
36-
PB_LINC = $(PB_INSTALL)/lib
35+
PB_HINC ?= $(PB_INSTALL)/include
36+
PB_LINC ?= $(PB_INSTALL)/lib
3737
PROTOC = $(PB_INSTALL)/bin/protoc
3838

39+
PB_HINC_I = $(addprefix -I, $(PB_HINC))
40+
PB_LINC_L = $(addprefix -L, $(PB_LINC))
41+
3942
export LD_LIBRARY_PATH=$(PB_LINC)
4043

4144
$(OCAMLOPTIONS_HINC)/ocamloptions.pb.cc: $(OCAMLOPTIONS_HINC)/ocamloptions.proto
4245
cd $(OCAMLOPTIONS_HINC) && \
43-
$(PROTOC) --cpp_out ./ -I ./ -I $(abspath $(PB_HINC)) ocamloptions.proto
46+
$(PROTOC) --cpp_out ./ -I ./ $(PB_HINC_I) ocamloptions.proto
4447

4548
%_cpp.tsk: %_cpp.cpp %.pb.cc $(OCAMLOPTIONS_HINC)/ocamloptions.pb.cc
4649
$(CXX) $(CPPFLAGS) $(LDFLAGS) \
47-
-I ./ -I $(INTEGRATION_TESTS_DIR) -I $(OCAMLOPTIONS_HINC) -I $(PB_HINC) \
48-
-L $(PB_LINC) -l protobuf \
50+
-I ./ -I $(INTEGRATION_TESTS_DIR) -I $(OCAMLOPTIONS_HINC) $(PB_HINC_L) \
51+
$(PB_LINC_L) $(PB_HINC_I) \
4952
$? \
50-
-o $@
53+
-o $@ -l protobuf
5154

5255
$(INTEGRATION_TESTS_DIR)/test10_cpp.tsk: \
5356
$(INTEGRATION_TESTS_DIR)/test10_cpp.cpp \
5457
$(INTEGRATION_TESTS_DIR)/test10.pb.cc \
5558
$(INTEGRATION_TESTS_DIR)/test09.pb.cc
5659
$(CXX) $(CPPFLAGS) $(LDFLAGS) \
57-
-I ./ -I $(INTEGRATION_TESTS_DIR) -I $(PB_HINC) \
58-
-L $(PB_LINC) -l protobuf \
60+
-I ./ -I $(INTEGRATION_TESTS_DIR) \
61+
$(PB_LINC_L) $(PB_HINC_I) \
5962
$? \
60-
-o $@
63+
-o $@ -l protobuf
6164

6265
.SECONDARY:
6366

6467
%.pb.cc: %.proto
6568
$(PROTOC) \
6669
--cpp_out $(INTEGRATION_TESTS_DIR) \
67-
-I $(PB_HINC) -I $(OCAMLOPTIONS_HINC) -I $(INTEGRATION_TESTS_DIR) \
70+
$(PB_HINC_I) -I $(OCAMLOPTIONS_HINC) -I $(INTEGRATION_TESTS_DIR) \
6871
$<
6972

7073

‎README.md

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
compiler**. See [here](https://github.com/mransan/bs-protobuf-demo) for complete example.
2525

2626

27-
2827
### A simple example
2928

3029
> This example generates the binary encoding, if you are more interested in a **JavaScript**

‎dep/Dockerfile

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM ocaml/opam:debian-ocaml-4.14 AS base
2+
3+
WORKDIR /build/
4+
RUN sudo chown -R opam: /build/
5+
RUN sudo apt install protobuf-compiler libprotobuf-dev -y
6+
COPY --chown=opam ./src/ ./src/
7+
COPY --chown=opam pbrt.opam pbrt_services.opam pbrt_yojson.opam ocaml-protoc.opam \
8+
Makefile Makefile.test dune-project dune .ocamlformat \
9+
.ocamlformat-ignore ./
10+
11+
RUN opam pin -n .
12+
RUN opam depext -yt ocaml-protoc
13+
RUN opam install -t . --deps-only
14+
15+
FROM base AS run-the-damn-build
16+
RUN opam exec -- dune build @install
17+
RUN opam exec -- dune runtest
18+
19+
# integration tests
20+
RUN opam install ppx_deriving -y
21+
RUN opam exec -- make clean build integration PB_LINC=/usr/lib/x86_64-linux-gnu/ PB_HINC=/usr/include/
22+

‎src/compilerlib/pb_codegen_all.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ let new_ocaml_mod ~proto_file_options ~proto_file_name () : ocaml_mod =
4848
in
4949

5050
(* write preludes *)
51-
F.line self.ml "[@@@ocaml.warning \"-27-30-39\"]";
51+
F.line self.ml "[@@@ocaml.warning \"-27-30-39-44\"]";
5252
F.empty_line self.ml;
5353
print_ppx self.ml;
5454
F.empty_line self.mli;

‎src/dune

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
(env
22
(_
33
(flags :standard -warn-error -a+8 -w +a-4-40-41-42-44-48-70)))
4+
5+
(data_only_dirs runtime-bs)

‎src/examples/build_server.ml.expected

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[@@@ocaml.warning "-27-30-39"]
1+
[@@@ocaml.warning "-27-30-39-44"]
22

33
type file_path = {
44
path : string;

‎src/examples/calculator.ml.expected

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[@@@ocaml.warning "-27-30-39"]
1+
[@@@ocaml.warning "-27-30-39-44"]
22

33
type div_by_zero = unit
44

‎src/examples/example01.ml.expected

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[@@@ocaml.warning "-27-30-39"]
1+
[@@@ocaml.warning "-27-30-39-44"]
22

33
type person = {
44
name : string;

‎src/examples/example03.ml.expected

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[@@@ocaml.warning "-27-30-39"]
1+
[@@@ocaml.warning "-27-30-39-44"]
22

33
type string_some_none = unit
44

‎src/examples/example04.ml.expected

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[@@@ocaml.warning "-27-30-39"]
1+
[@@@ocaml.warning "-27-30-39-44"]
22

33
type int_list_nil = unit
44

‎src/examples/example05.ml.expected

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[@@@ocaml.warning "-27-30-39"]
1+
[@@@ocaml.warning "-27-30-39-44"]
22

33
type person = {
44
name : string;

‎src/examples/file_server.ml.expected

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[@@@ocaml.warning "-27-30-39"]
1+
[@@@ocaml.warning "-27-30-39-44"]
22

33
type file_chunk = {
44
path : string;

‎src/examples/oneof.ml.expected

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[@@@ocaml.warning "-27-30-39"]
1+
[@@@ocaml.warning "-27-30-39-44"]
22

33
type patch_copy = {
44
start : int64;

‎src/examples/orgchart.ml.expected

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[@@@ocaml.warning "-27-30-39"]
1+
[@@@ocaml.warning "-27-30-39-44"]
22

33
type person = {
44
name : string;

‎src/runtime/stubs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ CAMLprim value caml_pbrt_varint_byte(value _str, value _idx, value _i) {
6565
CAMLparam3(_str, _idx, _i);
6666
char *str = Bytes_val(_str);
6767
int idx = Int_val(_idx);
68-
int64_t i = Int64_val(_idx);
68+
int64_t i = Int64_val(_i);
6969
pbrt_varint(str + idx, i);
7070
CAMLreturn(Val_unit);
7171
}

‎src/tests/benchmark/benchmark_single_ml.ml

+8-4
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ let make_test_requests ~number_of_sample test_ids =
4545
let file_name =
4646
Printf.sprintf "test_%s_%i.data" (string_of_test_id test_id) difficulty
4747
in
48-
let encode = Bench_t.{ type_ = Encode difficulty; file_name; test_id } in
49-
let decode = Bench_t.{ type_ = Decode; file_name; test_id } in
48+
let encode =
49+
Bench_t.{ type_ = { t = Some (Encode difficulty) }; file_name; test_id }
50+
in
51+
let decode =
52+
Bench_t.{ type_ = { t = Some Decode }; file_name; test_id }
53+
in
5054

5155
let init_cases, test_cases = acc in
5256
let test_cases = Util.append_n test_cases encode number_of_sample in
@@ -150,10 +154,10 @@ let print_compare_type ~metric responses test_ids =
150154
(fun data ->
151155
let open Bench_t in
152156
match data, metric with
153-
| Encode { encode_time; _ }, `Encode_time ->
157+
| Some (Encode { encode_time; _ }), `Encode_time ->
154158
sum := !sum +. encode_time;
155159
incr counter
156-
| Decode { decode_time; _ }, `Decode_time ->
160+
| Some (Decode { decode_time; _ }), `Decode_time ->
157161
sum := !sum +. decode_time;
158162
incr counter
159163
| _ -> ())

‎src/tests/benchmark/ocaml_test_runner.ml

+11-9
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ end
2727

2828
module Make (T : T_sig) : Runner_sig = struct
2929
let run { Benchmark.type_; file_name; test_id } =
30-
match type_ with
31-
| Benchmark.Encode difficulty ->
30+
match type_.t with
31+
| None -> failwith "missing benchmark"
32+
| Some (Encode difficulty) ->
3233
let t0 = Unix.gettimeofday () in
3334

3435
let encoder = Pbrt.Encoder.create () in
@@ -53,8 +54,8 @@ module Make (T : T_sig) : Runner_sig = struct
5354
}
5455
in
5556

56-
Benchmark.{ difficulty_size; test_id; data = Encode encode_data }
57-
| Benchmark.Decode ->
57+
Benchmark.{ difficulty_size; test_id; data = Some (Encode encode_data) }
58+
| Some Decode ->
5859
let t0 = Unix.gettimeofday () in
5960
let ic = open_in file_name in
6061
let len = in_channel_length ic in
@@ -69,11 +70,12 @@ module Make (T : T_sig) : Runner_sig = struct
6970
difficulty_size = T.difficulty_size v;
7071
test_id;
7172
data =
72-
Decode
73-
{
74-
Benchmark.from_file_time = t1 -. t0;
75-
Benchmark.decode_time = t2 -. t1;
76-
};
73+
Some
74+
(Decode
75+
{
76+
Benchmark.from_file_time = t1 -. t0;
77+
Benchmark.decode_time = t2 -. t1;
78+
});
7779
}
7880
end
7981
(* Make *)

‎src/tests/expectation/option_processing.ml.expected

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[@@@ocaml.warning "-27-30-39"]
1+
[@@@ocaml.warning "-27-30-39-44"]
22

33
type payment_system =
44
| Cash

0 commit comments

Comments
 (0)
Please sign in to comment.