Skip to content

Commit

Permalink
[3.15] backport mac CI fixes (#10571)
Browse files Browse the repository at this point in the history
* fix(test): silence duplicate -lc++ warnings on mac (#10468)

When linking C++ on recent macos versions, the linker will emit a
duplicate `-lc++` warning which we can silence in the test suite.

Signed-off-by: Etienne Millon <me@emillon.org>

* test: fixes to version-corruption.t (#10469)

* refactor(test): rewrite compare.sh in ocaml

This removes the external dependencies and makes intent clearer.
The count changes because it was counting the numbers of characters
differing in the hexdump instead of a byte count.

Signed-off-by: Etienne Millon <me@emillon.org>

* fix(test): disable version-corruption.t on mac

When codesigning triggers, the binary layout is completely changed to
it's not meaningful to count the number of changed bytes

Signed-off-by: Etienne Millon <me@emillon.org>

---------

Signed-off-by: Etienne Millon <me@emillon.org>

* ci: run build on macOS x86_64 again (#10481)

Signed-off-by: Antonio Nuno Monteiro <anmonteiro@gmail.com>

* test: fix truncate on macOS (#10361)

Signed-off-by: Thomas Gazagnaire <thomas@gazagnaire.org>

---------

Signed-off-by: Etienne Millon <me@emillon.org>
Signed-off-by: Antonio Nuno Monteiro <anmonteiro@gmail.com>
Signed-off-by: Thomas Gazagnaire <thomas@gazagnaire.org>
Co-authored-by: Antonio Nuno Monteiro <anmonteiro@gmail.com>
Co-authored-by: Thomas Gazagnaire <thomas@gazagnaire.org>
  • Loading branch information
3 people authored May 24, 2024
1 parent f76827f commit 35794f7
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 22 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ jobs:
- ocaml-compiler: 5.1.x
os: macos-latest
skip_test: true
# macOS x86_64 (Intel)
- ocaml-compiler: 4.14.x
os: macos-13
skip_test: true
# OCaml 4:
- ocaml-compiler: 4.13.x
os: ubuntu-latest
Expand Down
3 changes: 1 addition & 2 deletions test/blackbox-tests/test-cases/corrupt-persistent.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@

Delete last 10 chars of the .db file to corrupt it

$ truncate --size=-10 _build/.db
$ truncate -s -10 _build/.db

Dune log the corrupted file and recover

$ dune build a
$ grep "truncated object" _build/log
# Failed to load corrupted file _build/.db: input_value: truncated object

23 changes: 23 additions & 0 deletions test/blackbox-tests/test-cases/cxx-flags.t/dune
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,26 @@
(libraries quad)
(foreign_stubs (language cxx) (names bazexe))
(modules main))

(env
(_
(ocamlopt_flags
:standard
(:include extra_flags.sexp))))

(rule
(enabled_if
(or
(<> %{system} macosx)
(<> %{architecture} arm64)))
(action
(write-file extra_flags.sexp "()")))

; with XCode 15+, the linker complains about duplicate -lc++ libraries
(rule
(enabled_if
(and
(= %{system} macosx)
(= %{architecture} arm64)))
(action
(write-file extra_flags.sexp "(-ccopt -Wl,-no_warn_duplicate_libraries)")))
7 changes: 6 additions & 1 deletion test/blackbox-tests/test-cases/dune
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@

(cram
(applies_to version-corruption)
(deps %{bin:od} %{bin:git} %{bin:cmp} %{bin:sed} %{bin:chmod}))
(deps %{bin:git} %{bin:chmod})
(enabled_if
; code signing moves placeholders in the binary
(or
(<> %{system} macosx)
(<> %{architecture} arm64))))

(cram
(applies_to github8041)
Expand Down
48 changes: 29 additions & 19 deletions test/blackbox-tests/test-cases/version-corruption.t
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
Define a helper ./dump.sh unction with offsets removed, and one byte per line in
hex (so that the output is compiler version / alignment independent).
Define a helper program that counts how many bytes differ between two files.

$ cat >./dump.sh <<'EOF'
> set -eu
> od -v -A n -t x1 $1 | tr ' ' '\n' | sed '/^$/d'
$ cat > compare.ml << EOF
> let count_different_bytes s1 s2 =
> if String.length s1 <> String.length s2 then
> failwith "This test is only meaningful for files with the same length";
> let c = ref 0 in
> String.iteri (fun i c1 ->
> let c2 = String.unsafe_get s2 i in
> if not (Char.equal c1 c2) then
> incr c;
> ) s1;
> !c
>
> let read_all path = In_channel.with_open_bin path In_channel.input_all
>
> let () =
> let s1 = read_all Sys.argv.(1) in
> let s2 = read_all Sys.argv.(2) in
> let n = count_different_bytes s1 s2 in
> Printf.printf "%d\n" n
> EOF
$ chmod +x ./dump.sh
$ cat >./compare.sh <<'EOF'
> set -eu
> ./dump.sh $1 >$1.dump
> ./dump.sh $2 >$2.dump
> cmp -l $1.dump $2.dump | wc -l | sed -e 's/^ *//'
> EOF
$ chmod +x compare.sh

A repro that builds and installs multiple binaries, and promotes a bytecode and
native executable in same rule (this is very likely to detect corruption with
Expand Down Expand Up @@ -97,12 +104,15 @@ shared buffer):
$ rm -f gen_lifecycle.bc gen_lifecycle.exe && dune clean && dune build && ./gen_lifecycle.exe >/dev/null
$ cp _build/default/gen_lifecycle.exe gen_lifecycle.old

We compare the substituted version with the original. The expected value is 64,
which corresponds to `~min_len` in Link_time_code_gen.

$ dune install -j16 --prefix=./_install
$ ./compare.sh _build/default/gen1.exe _install/bin/gen1
100
$ ocaml ./compare.ml _build/default/gen1.exe _install/bin/gen1
64

$ ./compare.sh _build/default/gen2.bc _install/bin/gen2
100
$ ocaml compare.ml _build/default/gen2.bc _install/bin/gen2
64

$ dune build --debug-artifact-substitution
Found placeholder in _build/default/gen_lifecycle.exe:
Expand All @@ -112,8 +122,8 @@ shared buffer):
- placeholder: Vcs_describe In_source_tree "."
- evaluates to: "v0.0.1"

$ ./compare.sh gen_lifecycle.old ./gen_lifecycle.exe
100
$ ocaml compare.ml gen_lifecycle.old ./gen_lifecycle.exe
64

$ ./gen_lifecycle.exe
0.0.1
Expand Down

0 comments on commit 35794f7

Please sign in to comment.