Skip to content

Commit

Permalink
Merge branch 'main' into action-binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
emillon authored May 3, 2024
2 parents 8ba4e91 + cacaad3 commit 7b380de
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
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 corrupt-persistent)
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 7b380de

Please sign in to comment.