Unverified Commit 511b9c68 authored by Michael Müller's avatar Michael Müller Committed by GitHub
Browse files

Fix code coverage (#917)

* Add `-Clink-dead-code`

* Test trait cross-call only when not measuring code coverage

Otherwise a linker error will happen due
to `__ink_enforce_error` being included.

* Fix `clippy::derivable_impls`

* Fix `dead_code`

The `struct` is only a public-facing API.

* Fix yaml

* Remove `allow(dead_code)`

* Actually use `$POLL_SLEEP`

* Produce `unreachable!` instead of linker error for `codecov` CI stage

* Move `if` condition outside of `quote`

* Improve macro hygiene

* Reduce code duplication
parent b4e2781c
Pipeline #158616 passed with stages
in 24 minutes and 29 seconds
......@@ -220,10 +220,11 @@ codecov:
variables:
# For codecov it's sufficient to run the fuzz tests only once.
QUICKCHECK_TESTS: 1
INK_COVERAGE_REPORTING: "true"
CARGO_INCREMENTAL: 0
# Variables partly came from https://github.com/mozilla/grcov/blob/master/README.md
RUSTFLAGS: "-Zprofile -Zmir-opt-level=0 -Ccodegen-units=1
-Copt-level=0 -Coverflow-checks=off"
-Clink-dead-code -Copt-level=0 -Coverflow-checks=off"
# The `cargo-taurpalin` coverage reporting tool seems to have better code instrumentation and thus
# produces better results for Rust codebases in general. However, unlike `grcov` it requires
# running docker with `--security-opt seccomp=unconfined` which is why we use `grcov` instead.
......
......@@ -243,6 +243,25 @@ impl CrossCalling<'_> {
ir::Receiver::Ref => None,
ir::Receiver::RefMut => Some(quote! { mut }),
};
let error_ident = match option_env!("INK_COVERAGE_REPORTING") {
Some("true") => {
quote! {
// The code coverage reporting CI stage links dead code,
// hence we have to provide an `unreachable!` here. If
// the invalid implementation above is linked this results
// in a linker error.
::core::unreachable!("this is an invalid ink! message call which should never be possible.");
}
}
_ => {
quote! {
extern {
fn #linker_error_ident() -> !;
}
unsafe { #linker_error_ident() }
}
}
};
quote_spanned!(span=>
type #output_ident = #output_ty;
......@@ -253,10 +272,7 @@ impl CrossCalling<'_> {
& #mut_tok self,
#( #input_bindings : #input_types ),*
) -> Self::#output_ident {
extern {
fn #linker_error_ident() -> !;
}
unsafe { #linker_error_ident() }
#error_ident
}
)
}
......@@ -377,6 +393,25 @@ impl CrossCalling<'_> {
.inputs()
.map(|pat_type| &*pat_type.ty)
.collect::<Vec<_>>();
let error_ident = match option_env!("INK_COVERAGE_REPORTING") {
Some("true") => {
quote! {
// The code coverage reporting CI stage links dead code,
// hence we have to provide an `unreachable!` here. If
// the invalid implementation above is linked this results
// in a linker error.
::core::unreachable!("this is an invalid ink! message call which should never be possible.");
}
}
_ => {
quote! {
extern {
fn #linker_error_ident() -> !;
}
unsafe { #linker_error_ident() }
}
}
};
quote_spanned!(span =>
type #output_ident = ::ink_lang::NeverReturns;
......@@ -386,10 +421,7 @@ impl CrossCalling<'_> {
fn #ident(
#( #input_bindings : #input_types ),*
) -> Self::#output_ident {
extern {
fn #linker_error_ident() -> !;
}
unsafe { #linker_error_ident() }
#error_ident
}
)
}
......
......@@ -62,7 +62,7 @@ for i in $(seq 1 $SEQ_END); do
else
echo "Something else has happened in ${PIPELINE_URL}"; exit 1;
fi
sleep 5;
sleep $POLL_SLEEP;
done
echo "Timeout! The pipeline didn't return in time."
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment