From 1f423a6e42cc2eb868fefbab1b3d81e152b34186 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Tue, 2 Dec 2025 20:49:26 +1100 Subject: [PATCH] coverage: Add a test for macros that only contain other macros --- tests/coverage/macros/pass-through.cov-map | 57 +++++++++++++++++ tests/coverage/macros/pass-through.coverage | 71 +++++++++++++++++++++ tests/coverage/macros/pass-through.rs | 70 ++++++++++++++++++++ 3 files changed, 198 insertions(+) create mode 100644 tests/coverage/macros/pass-through.cov-map create mode 100644 tests/coverage/macros/pass-through.coverage create mode 100644 tests/coverage/macros/pass-through.rs diff --git a/tests/coverage/macros/pass-through.cov-map b/tests/coverage/macros/pass-through.cov-map new file mode 100644 index 000000000000..83937e4fb8b7 --- /dev/null +++ b/tests/coverage/macros/pass-through.cov-map @@ -0,0 +1,57 @@ +Function name: pass_through::uses_inner_macro +Raw bytes (51): 0x[01, 01, 01, 01, 05, 09, 01, 24, 01, 00, 16, 01, 01, 08, 00, 1d, 05, 01, 09, 00, 0c, 05, 00, 0d, 00, 21, 05, 01, 09, 00, 15, 05, 01, 09, 00, 0c, 05, 00, 0d, 00, 20, 02, 01, 05, 00, 06, 01, 01, 01, 00, 02] +Number of files: 1 +- file 0 => $DIR/pass-through.rs +Number of expressions: 1 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +Number of file 0 mappings: 9 +- Code(Counter(0)) at (prev + 36, 1) to (start + 0, 22) +- Code(Counter(0)) at (prev + 1, 8) to (start + 0, 29) +- Code(Counter(1)) at (prev + 1, 9) to (start + 0, 12) +- Code(Counter(1)) at (prev + 0, 13) to (start + 0, 33) +- Code(Counter(1)) at (prev + 1, 9) to (start + 0, 21) +- Code(Counter(1)) at (prev + 1, 9) to (start + 0, 12) +- Code(Counter(1)) at (prev + 0, 13) to (start + 0, 32) +- Code(Expression(0, Sub)) at (prev + 1, 5) to (start + 0, 6) + = (c0 - c1) +- Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) +Highest counter ID seen: c1 + +Function name: pass_through::uses_middle_macro +Raw bytes (51): 0x[01, 01, 01, 01, 05, 09, 01, 2c, 01, 00, 17, 01, 01, 08, 00, 1d, 05, 01, 09, 00, 0c, 05, 00, 0d, 00, 22, 05, 01, 09, 00, 16, 05, 01, 09, 00, 0c, 05, 00, 0d, 00, 21, 02, 01, 05, 00, 06, 01, 01, 01, 00, 02] +Number of files: 1 +- file 0 => $DIR/pass-through.rs +Number of expressions: 1 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +Number of file 0 mappings: 9 +- Code(Counter(0)) at (prev + 44, 1) to (start + 0, 23) +- Code(Counter(0)) at (prev + 1, 8) to (start + 0, 29) +- Code(Counter(1)) at (prev + 1, 9) to (start + 0, 12) +- Code(Counter(1)) at (prev + 0, 13) to (start + 0, 34) +- Code(Counter(1)) at (prev + 1, 9) to (start + 0, 22) +- Code(Counter(1)) at (prev + 1, 9) to (start + 0, 12) +- Code(Counter(1)) at (prev + 0, 13) to (start + 0, 33) +- Code(Expression(0, Sub)) at (prev + 1, 5) to (start + 0, 6) + = (c0 - c1) +- Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) +Highest counter ID seen: c1 + +Function name: pass_through::uses_outer_macro +Raw bytes (51): 0x[01, 01, 01, 01, 05, 09, 01, 34, 01, 00, 16, 01, 01, 08, 00, 1d, 05, 01, 09, 00, 0c, 05, 00, 0d, 00, 21, 05, 01, 09, 00, 15, 05, 01, 09, 00, 0c, 05, 00, 0d, 00, 20, 02, 01, 05, 00, 06, 01, 01, 01, 00, 02] +Number of files: 1 +- file 0 => $DIR/pass-through.rs +Number of expressions: 1 +- expression 0 operands: lhs = Counter(0), rhs = Counter(1) +Number of file 0 mappings: 9 +- Code(Counter(0)) at (prev + 52, 1) to (start + 0, 22) +- Code(Counter(0)) at (prev + 1, 8) to (start + 0, 29) +- Code(Counter(1)) at (prev + 1, 9) to (start + 0, 12) +- Code(Counter(1)) at (prev + 0, 13) to (start + 0, 33) +- Code(Counter(1)) at (prev + 1, 9) to (start + 0, 21) +- Code(Counter(1)) at (prev + 1, 9) to (start + 0, 12) +- Code(Counter(1)) at (prev + 0, 13) to (start + 0, 32) +- Code(Expression(0, Sub)) at (prev + 1, 5) to (start + 0, 6) + = (c0 - c1) +- Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2) +Highest counter ID seen: c1 + diff --git a/tests/coverage/macros/pass-through.coverage b/tests/coverage/macros/pass-through.coverage new file mode 100644 index 000000000000..f1adb235f74a --- /dev/null +++ b/tests/coverage/macros/pass-through.coverage @@ -0,0 +1,71 @@ + LL| |#![feature(coverage_attribute)] + LL| |//@ edition: 2024 + LL| | + LL| |// Test that when a macro expands to another macro, without any significant + LL| |// spans of its own, that this doesn't cause coverage instrumentation to give + LL| |// up and ignore the inner spans. + LL| | + LL| |macro_rules! inner_macro { + LL| | () => { + LL| | if core::hint::black_box(true) { + LL| | say("true"); + LL| | } else { + LL| | say("false"); + LL| | } + LL| | }; + LL| |} + LL| | + LL| |macro_rules! middle_macro { + LL| | () => { + LL| | inner_macro!() + LL| | }; + LL| |} + LL| | + LL| |macro_rules! outer_macro { + LL| | () => { + LL| | middle_macro!() + LL| | }; + LL| |} + LL| | + LL| |// In each of these three functions, the macro call should be instrumented, + LL| |// and should have an execution count of 1. + LL| |// + LL| |// Each function contains some extra code to ensure that control flow is + LL| |// non-trivial. + LL| | + LL| 1|fn uses_inner_macro() { + LL| 1| if core::hint::black_box(true) { + LL| 1| say("before inner_macro"); + LL| 1| inner_macro!(); + LL| 1| say("after inner_macro"); + LL| 0| } + LL| 1|} + LL| | + LL| 1|fn uses_middle_macro() { + LL| 1| if core::hint::black_box(true) { + LL| 1| say("before middle_macro"); + LL| 1| middle_macro!(); + LL| 1| say("after middle_macro") + LL| 0| } + LL| 1|} + LL| | + LL| 1|fn uses_outer_macro() { + LL| 1| if core::hint::black_box(true) { + LL| 1| say("before outer_macro"); + LL| 1| outer_macro!(); + LL| 1| say("after outer_macro"); + LL| 0| } + LL| 1|} + LL| | + LL| |#[coverage(off)] + LL| |fn main() { + LL| | uses_inner_macro(); + LL| | uses_middle_macro(); + LL| | uses_outer_macro(); + LL| |} + LL| | + LL| |#[coverage(off)] + LL| |fn say(message: &str) { + LL| | println!("{message}"); + LL| |} + diff --git a/tests/coverage/macros/pass-through.rs b/tests/coverage/macros/pass-through.rs new file mode 100644 index 000000000000..6e5ad3d93b73 --- /dev/null +++ b/tests/coverage/macros/pass-through.rs @@ -0,0 +1,70 @@ +#![feature(coverage_attribute)] +//@ edition: 2024 + +// Test that when a macro expands to another macro, without any significant +// spans of its own, that this doesn't cause coverage instrumentation to give +// up and ignore the inner spans. + +macro_rules! inner_macro { + () => { + if core::hint::black_box(true) { + say("true"); + } else { + say("false"); + } + }; +} + +macro_rules! middle_macro { + () => { + inner_macro!() + }; +} + +macro_rules! outer_macro { + () => { + middle_macro!() + }; +} + +// In each of these three functions, the macro call should be instrumented, +// and should have an execution count of 1. +// +// Each function contains some extra code to ensure that control flow is +// non-trivial. + +fn uses_inner_macro() { + if core::hint::black_box(true) { + say("before inner_macro"); + inner_macro!(); + say("after inner_macro"); + } +} + +fn uses_middle_macro() { + if core::hint::black_box(true) { + say("before middle_macro"); + middle_macro!(); + say("after middle_macro") + } +} + +fn uses_outer_macro() { + if core::hint::black_box(true) { + say("before outer_macro"); + outer_macro!(); + say("after outer_macro"); + } +} + +#[coverage(off)] +fn main() { + uses_inner_macro(); + uses_middle_macro(); + uses_outer_macro(); +} + +#[coverage(off)] +fn say(message: &str) { + println!("{message}"); +}