From f83f7966f5a9cadffd0b9ef115e0834bbef2d0dd Mon Sep 17 00:00:00 2001 From: Zalathar Date: Sun, 22 Oct 2023 17:05:27 +1100 Subject: [PATCH 1/2] coverage: Add UI tests for values accepted by `-Cinstrument-coverage` --- src/tools/tidy/src/ui_tests.rs | 2 +- tests/codegen/instrument-coverage-off.rs | 23 +++++++++++++++++++ tests/codegen/instrument-coverage.rs | 9 +++++++- .../instrument-coverage/bad-value.bad.stderr | 2 ++ .../bad-value.blank.stderr | 2 ++ tests/ui/instrument-coverage/bad-value.rs | 5 ++++ .../except-unused-functions.rs | 3 +++ .../except-unused-functions.stderr | 2 ++ .../except-unused-generics.rs | 3 +++ .../except-unused-generics.stderr | 2 ++ tests/ui/instrument-coverage/off-values.rs | 9 ++++++++ tests/ui/instrument-coverage/on-values.rs | 11 +++++++++ 12 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 tests/codegen/instrument-coverage-off.rs create mode 100644 tests/ui/instrument-coverage/bad-value.bad.stderr create mode 100644 tests/ui/instrument-coverage/bad-value.blank.stderr create mode 100644 tests/ui/instrument-coverage/bad-value.rs create mode 100644 tests/ui/instrument-coverage/except-unused-functions.rs create mode 100644 tests/ui/instrument-coverage/except-unused-functions.stderr create mode 100644 tests/ui/instrument-coverage/except-unused-generics.rs create mode 100644 tests/ui/instrument-coverage/except-unused-generics.stderr create mode 100644 tests/ui/instrument-coverage/off-values.rs create mode 100644 tests/ui/instrument-coverage/on-values.rs diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs index 2b828e58d54..dcf218bc189 100644 --- a/src/tools/tidy/src/ui_tests.rs +++ b/src/tools/tidy/src/ui_tests.rs @@ -11,7 +11,7 @@ use std::path::{Path, PathBuf}; const ENTRY_LIMIT: usize = 900; // FIXME: The following limits should be reduced eventually. const ISSUES_ENTRY_LIMIT: usize = 1854; -const ROOT_ENTRY_LIMIT: usize = 865; +const ROOT_ENTRY_LIMIT: usize = 866; const EXPECTED_TEST_FILE_EXTENSIONS: &[&str] = &[ "rs", // test source files diff --git a/tests/codegen/instrument-coverage-off.rs b/tests/codegen/instrument-coverage-off.rs new file mode 100644 index 00000000000..ca803beec0b --- /dev/null +++ b/tests/codegen/instrument-coverage-off.rs @@ -0,0 +1,23 @@ +// Test that `-Cinstrument-coverage=off` does not add coverage instrumentation to LLVM IR. + +// needs-profiler-support +// revisions: n no off false zero +// [n] compile-flags: -Cinstrument-coverage=n +// [no] compile-flags: -Cinstrument-coverage=no +// [off] compile-flags: -Cinstrument-coverage=off +// [false] compile-flags: -Cinstrument-coverage=false +// [zero] compile-flags: -Cinstrument-coverage=0 + +// CHECK-NOT: __llvm_profile_filename +// CHECK-NOT: __llvm_coverage_mapping + +#![crate_type="lib"] + +#[inline(never)] +fn some_function() { + +} + +pub fn some_other_function() { + some_function(); +} diff --git a/tests/codegen/instrument-coverage.rs b/tests/codegen/instrument-coverage.rs index 78f8875a2d9..f8437dac463 100644 --- a/tests/codegen/instrument-coverage.rs +++ b/tests/codegen/instrument-coverage.rs @@ -1,9 +1,16 @@ // Test that `-Cinstrument-coverage` creates expected __llvm_profile_filename symbol in LLVM IR. // needs-profiler-support -// compile-flags: -Cinstrument-coverage +// revisions: default y yes on true all +// [default] compile-flags: -Cinstrument-coverage +// [y] compile-flags: -Cinstrument-coverage=y +// [yes] compile-flags: -Cinstrument-coverage=yes +// [on] compile-flags: -Cinstrument-coverage=on +// [true] compile-flags: -Cinstrument-coverage=true +// [all] compile-flags: -Cinstrument-coverage=all // CHECK: @__llvm_profile_filename = {{.*}}"default_%m_%p.profraw\00"{{.*}} +// CHECK: @__llvm_coverage_mapping #![crate_type="lib"] diff --git a/tests/ui/instrument-coverage/bad-value.bad.stderr b/tests/ui/instrument-coverage/bad-value.bad.stderr new file mode 100644 index 00000000000..246c4f31a4b --- /dev/null +++ b/tests/ui/instrument-coverage/bad-value.bad.stderr @@ -0,0 +1,2 @@ +error: incorrect value `bad-value` for codegen option `instrument-coverage` - `all` (default), `except-unused-generics`, `except-unused-functions`, or `off` was expected + diff --git a/tests/ui/instrument-coverage/bad-value.blank.stderr b/tests/ui/instrument-coverage/bad-value.blank.stderr new file mode 100644 index 00000000000..b539c558d9b --- /dev/null +++ b/tests/ui/instrument-coverage/bad-value.blank.stderr @@ -0,0 +1,2 @@ +error: incorrect value `` for codegen option `instrument-coverage` - `all` (default), `except-unused-generics`, `except-unused-functions`, or `off` was expected + diff --git a/tests/ui/instrument-coverage/bad-value.rs b/tests/ui/instrument-coverage/bad-value.rs new file mode 100644 index 00000000000..1925c36aa53 --- /dev/null +++ b/tests/ui/instrument-coverage/bad-value.rs @@ -0,0 +1,5 @@ +// revisions: blank bad +// [blank] compile-flags: -Cinstrument-coverage= +// [bad] compile-flags: -Cinstrument-coverage=bad-value + +fn main() {} diff --git a/tests/ui/instrument-coverage/except-unused-functions.rs b/tests/ui/instrument-coverage/except-unused-functions.rs new file mode 100644 index 00000000000..5a0b7d4fef9 --- /dev/null +++ b/tests/ui/instrument-coverage/except-unused-functions.rs @@ -0,0 +1,3 @@ +// compile-flags: -Cinstrument-coverage=except-unused-functions + +fn main() {} diff --git a/tests/ui/instrument-coverage/except-unused-functions.stderr b/tests/ui/instrument-coverage/except-unused-functions.stderr new file mode 100644 index 00000000000..82c1c630cbf --- /dev/null +++ b/tests/ui/instrument-coverage/except-unused-functions.stderr @@ -0,0 +1,2 @@ +error: `-C instrument-coverage=except-*` requires `-Z unstable-options` + diff --git a/tests/ui/instrument-coverage/except-unused-generics.rs b/tests/ui/instrument-coverage/except-unused-generics.rs new file mode 100644 index 00000000000..4b1ddf29026 --- /dev/null +++ b/tests/ui/instrument-coverage/except-unused-generics.rs @@ -0,0 +1,3 @@ +// compile-flags: -Cinstrument-coverage=except-unused-generics + +fn main() {} diff --git a/tests/ui/instrument-coverage/except-unused-generics.stderr b/tests/ui/instrument-coverage/except-unused-generics.stderr new file mode 100644 index 00000000000..82c1c630cbf --- /dev/null +++ b/tests/ui/instrument-coverage/except-unused-generics.stderr @@ -0,0 +1,2 @@ +error: `-C instrument-coverage=except-*` requires `-Z unstable-options` + diff --git a/tests/ui/instrument-coverage/off-values.rs b/tests/ui/instrument-coverage/off-values.rs new file mode 100644 index 00000000000..0f9a0c47425 --- /dev/null +++ b/tests/ui/instrument-coverage/off-values.rs @@ -0,0 +1,9 @@ +// check-pass +// revisions: n no off false zero +// [n] compile-flags: -Cinstrument-coverage=n +// [no] compile-flags: -Cinstrument-coverage=no +// [off] compile-flags: -Cinstrument-coverage=off +// [false] compile-flags: -Cinstrument-coverage=false +// [zero] compile-flags: -Cinstrument-coverage=0 + +fn main() {} diff --git a/tests/ui/instrument-coverage/on-values.rs b/tests/ui/instrument-coverage/on-values.rs new file mode 100644 index 00000000000..cc54c71c656 --- /dev/null +++ b/tests/ui/instrument-coverage/on-values.rs @@ -0,0 +1,11 @@ +// check-pass +// needs-profiler-support +// revisions: default y yes on true all +// [default] compile-flags: -Cinstrument-coverage +// [y] compile-flags: -Cinstrument-coverage=y +// [yes] compile-flags: -Cinstrument-coverage=yes +// [on] compile-flags: -Cinstrument-coverage=on +// [true] compile-flags: -Cinstrument-coverage=true +// [all] compile-flags: -Cinstrument-coverage=all + +fn main() {} From 71b7322440aaba17a163bcb962e5c8cb07239725 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Sun, 22 Oct 2023 18:35:14 +1100 Subject: [PATCH 2/2] Fix comment: coverage-map tests compile to LLVM IR, not MIR --- src/tools/compiletest/src/runtest.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 8ce00e00b57..ac270a1f0ba 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2470,7 +2470,7 @@ impl<'test> TestCx<'test> { } CoverageMap => { rustc.arg("-Cinstrument-coverage"); - // These tests only compile to MIR, so they don't need the + // These tests only compile to LLVM IR, so they don't need the // profiler runtime to be present. rustc.arg("-Zno-profiler-runtime"); // Coverage mappings are sensitive to MIR optimizations, and