Skip to content

Commit 80e8db8

Browse files
committed
tests: Require run-fail ui tests to have an exit code (SIGABRT not ok)
Normally a `run-fail` ui test shall not be terminated by a signal like SIGABRT. So begin having that as a hard requirement. Some of our current tests do terminate by a signal however. Introduce and use `run-crash` for those tests.
1 parent 8cf5fad commit 80e8db8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+129
-80
lines changed

src/doc/rustc-dev-guide/src/tests/directives.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ expectations](ui.md#controlling-passfail-expectations).
7575
| `check-fail` | Building (no codegen) should fail | `ui`, `crashes` | N/A |
7676
| `build-pass` | Building should pass | `ui`, `crashes`, `codegen`, `incremental` | N/A |
7777
| `build-fail` | Building should fail | `ui`, `crashes` | N/A |
78-
| `run-pass` | Running the test binary should pass | `ui`, `crashes`, `incremental` | N/A |
79-
| `run-fail` | Running the test binary should fail | `ui`, `crashes` | N/A |
78+
| `run-pass` | Program must exit with code `0` | `ui`, `crashes`, `incremental` | N/A |
79+
| `run-fail` | Program must exit with code `1..=127` | `ui`, `crashes` | N/A |
80+
| `run-crash` | Program must crash | `ui`, | N/A |
8081
| `ignore-pass` | Ignore `--pass` flag | `ui`, `crashes`, `codegen`, `incremental` | N/A |
8182
| `dont-check-failure-status` | Don't check exact failure status (i.e. `1`) | `ui`, `incremental` | N/A |
8283
| `failure-status` | Check | `ui`, `crashes` | Any `u16` |

src/doc/rustc-dev-guide/src/tests/ui.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ even run the resulting program. Just add one of the following
443443
- `//@ build-pass` — compilation and linking should succeed but do
444444
not run the resulting binary.
445445
- `//@ run-pass` — compilation should succeed and running the resulting
446-
binary should also succeed.
446+
binary should make it exit with code 0 which indicates success.
447447
- Fail directives:
448448
- `//@ check-fail` — compilation should fail (the codegen phase is skipped).
449449
This is the default for UI tests.
@@ -452,7 +452,10 @@ even run the resulting program. Just add one of the following
452452
without the codegen phase, then a second time the full compile should
453453
fail.
454454
- `//@ run-fail` — compilation should succeed, but running the resulting
455-
binary should fail.
455+
binary should make it exit with a code in the `1..=127` which indicates
456+
regular failure.
457+
- `//@ run-crash` — compilation should succeed, but running the resulting
458+
binary should fail with a crash (e.g. `SIGABRT` or `SIGSEGV`).
456459

457460
For `run-pass` and `run-fail` tests, by default the output of the program itself
458461
is not checked.

src/tools/compiletest/src/common.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,23 @@ string_enum! {
110110
}
111111
}
112112

113+
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
114+
pub enum RunFailMode {
115+
/// Running the program must make it exit with a regular failure exit code
116+
/// in the range `1..=127`. If the program is terminated by e.g. a signal
117+
/// the test will fail.
118+
ExitWithFailure,
119+
/// Running the program must result in a crash, e.g. by `SIGABRT` or
120+
/// `SIGSEGV` on Unix or on Windows by having an appropriate NTSTATUS high
121+
/// bit in the exit code.
122+
Crash,
123+
}
124+
113125
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
114126
pub enum FailMode {
115127
Check,
116128
Build,
117-
Run,
129+
Run(RunFailMode),
118130
}
119131

120132
string_enum! {

src/tools/compiletest/src/directive-list.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
241241
"regex-error-pattern",
242242
"remap-src-base",
243243
"revisions",
244+
"run-crash",
244245
"run-fail",
245246
"run-flags",
246247
"run-pass",

src/tools/compiletest/src/header.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use camino::{Utf8Path, Utf8PathBuf};
99
use semver::Version;
1010
use tracing::*;
1111

12-
use crate::common::{Config, Debugger, FailMode, Mode, PassMode};
12+
use crate::common::{Config, Debugger, FailMode, Mode, PassMode, RunFailMode};
1313
use crate::debuggers::{extract_cdb_version, extract_gdb_version};
1414
use crate::errors::ErrorKind;
1515
use crate::executor::{CollectedTestDesc, ShouldPanic};
@@ -655,7 +655,10 @@ impl TestProps {
655655
Some(FailMode::Build)
656656
} else if config.parse_name_directive(ln, "run-fail") {
657657
check_ui("run");
658-
Some(FailMode::Run)
658+
Some(FailMode::Run(RunFailMode::ExitWithFailure))
659+
} else if config.parse_name_directive(ln, "run-crash") {
660+
check_ui("run");
661+
Some(FailMode::Run(RunFailMode::Crash))
659662
} else {
660663
None
661664
};

src/tools/compiletest/src/runtest.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ use tracing::*;
1717

1818
use crate::common::{
1919
Assembly, Codegen, CodegenUnits, CompareMode, Config, CoverageMap, CoverageRun, Crashes,
20-
DebugInfo, Debugger, FailMode, Incremental, MirOpt, PassMode, Pretty, RunMake, Rustdoc,
21-
RustdocJs, RustdocJson, TestPaths, UI_EXTENSIONS, UI_FIXED, UI_RUN_STDERR, UI_RUN_STDOUT,
22-
UI_STDERR, UI_STDOUT, UI_SVG, UI_WINDOWS_SVG, Ui, expected_output_path, incremental_dir,
23-
output_base_dir, output_base_name, output_testname_unique,
20+
DebugInfo, Debugger, FailMode, Incremental, MirOpt, PassMode, Pretty, RunFailMode, RunMake,
21+
Rustdoc, RustdocJs, RustdocJson, TestPaths, UI_EXTENSIONS, UI_FIXED, UI_RUN_STDERR,
22+
UI_RUN_STDOUT, UI_STDERR, UI_STDOUT, UI_SVG, UI_WINDOWS_SVG, Ui, expected_output_path,
23+
incremental_dir, output_base_dir, output_base_name, output_testname_unique,
2424
};
2525
use crate::compute_diff::{DiffLine, make_diff, write_diff, write_filtered_diff};
2626
use crate::errors::{Error, ErrorKind, load_errors};
@@ -277,7 +277,11 @@ impl<'test> TestCx<'test> {
277277

278278
fn should_run(&self, pm: Option<PassMode>) -> WillExecute {
279279
let test_should_run = match self.config.mode {
280-
Ui if pm == Some(PassMode::Run) || self.props.fail_mode == Some(FailMode::Run) => true,
280+
Ui if pm == Some(PassMode::Run)
281+
|| matches!(self.props.fail_mode, Some(FailMode::Run(_))) =>
282+
{
283+
true
284+
}
281285
MirOpt if pm == Some(PassMode::Run) => true,
282286
Ui | MirOpt => false,
283287
mode => panic!("unimplemented for mode {:?}", mode),
@@ -296,6 +300,13 @@ impl<'test> TestCx<'test> {
296300
}
297301
}
298302

303+
fn should_exit_with_failure(&self) -> bool {
304+
match self.config.mode {
305+
Ui => self.props.fail_mode == Some(FailMode::Run(RunFailMode::ExitWithFailure)),
306+
mode => panic!("unimplemented for mode {:?}", mode),
307+
}
308+
}
309+
299310
fn should_compile_successfully(&self, pm: Option<PassMode>) -> bool {
300311
match self.config.mode {
301312
RustdocJs => true,

src/tools/compiletest/src/runtest/ui.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,32 @@ impl TestCx<'_> {
140140
&proc_res,
141141
);
142142
}
143+
let code = proc_res.status.code();
144+
let exit_with_success = proc_res.status.success();
145+
// A normal failure exit code is between 1 and 127. If we don't have
146+
// an exit code or if it is outside that range (and not 0) we
147+
// consider it a crash.
148+
let exit_with_failure = code.is_some_and(|c| c >= 1 && c <= 127);
143149
if self.should_run_successfully(pm) {
144-
if !proc_res.status.success() {
145-
self.fatal_proc_rec("test run failed!", &proc_res);
150+
if !exit_with_success {
151+
self.fatal_proc_rec(&format!("test run failed! code={code:?}"), &proc_res);
152+
}
153+
} else if self.should_exit_with_failure() {
154+
if !exit_with_failure {
155+
self.fatal_proc_rec(
156+
&format!("test did not exit with failure! code={code:?}"),
157+
&proc_res,
158+
);
159+
}
160+
} else {
161+
// If we get here it means we should not run successfully and we
162+
// should not exit with failure. So we should crash. And if we
163+
// did exit with success or did exit with failure it means we
164+
// did NOT crash.
165+
if exit_with_success || exit_with_failure {
166+
self.fatal_proc_rec(&format!("test did not crash! code={code:?}"), &proc_res);
146167
}
147-
} else if proc_res.status.success() {
148-
self.fatal_proc_rec("test run succeeded!", &proc_res);
149168
}
150-
151169
self.get_output(&proc_res)
152170
} else {
153171
self.get_output(&proc_res)

tests/ui/contracts/contract-attributes-generics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
//@ [unchk_pass] run-pass
66
//@ [chk_pass] run-pass
77
//
8-
//@ [chk_fail_pre] run-fail
9-
//@ [chk_fail_post] run-fail
10-
//@ [chk_const_fail] run-fail
8+
//@ [chk_fail_pre] run-crash
9+
//@ [chk_fail_post] run-crash
10+
//@ [chk_const_fail] run-crash
1111
//
1212
//@ [unchk_pass] compile-flags: -Zcontract-checks=no
1313
//

tests/ui/contracts/contract-attributes-nest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
//@ [unchk_fail_post] run-pass
66
//@ [chk_pass] run-pass
77
//
8-
//@ [chk_fail_pre] run-fail
9-
//@ [chk_fail_post] run-fail
8+
//@ [chk_fail_pre] run-crash
9+
//@ [chk_fail_post] run-crash
1010
//
1111
//@ [unchk_pass] compile-flags: -Zcontract-checks=no
1212
//@ [unchk_fail_pre] compile-flags: -Zcontract-checks=no

tests/ui/contracts/contract-attributes-tail.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
//@ [unchk_fail_post] run-pass
66
//@ [chk_pass] run-pass
77
//
8-
//@ [chk_fail_pre] run-fail
9-
//@ [chk_fail_post] run-fail
8+
//@ [chk_fail_pre] run-crash
9+
//@ [chk_fail_post] run-crash
1010
//
1111
//@ [unchk_pass] compile-flags: -Zcontract-checks=no
1212
//@ [unchk_fail_pre] compile-flags: -Zcontract-checks=no

tests/ui/contracts/contract-captures-via-closure-copy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ run-fail
1+
//@ run-crash
22
//@ compile-flags: -Zcontract-checks=yes
33

44
#![feature(contracts)]

tests/ui/contracts/contract-const-fn.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
//
99
//@ [all_pass] run-pass
1010
//
11-
//@ [runtime_fail_pre] run-fail
12-
//@ [runtime_fail_post] run-fail
11+
//@ [runtime_fail_pre] run-crash
12+
//@ [runtime_fail_post] run-crash
1313
//
1414
//@ [all_pass] compile-flags: -Zcontract-checks=yes
1515
//@ [runtime_fail_pre] compile-flags: -Zcontract-checks=yes

tests/ui/contracts/contracts-ensures-early-fn-exit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
//
33
//@ [unchk_pass] run-pass
44
//@ [chk_pass] run-pass
5-
//@ [chk_fail_try] run-fail
6-
//@ [chk_fail_ret] run-fail
7-
//@ [chk_fail_yeet] run-fail
5+
//@ [chk_fail_try] run-crash
6+
//@ [chk_fail_ret] run-crash
7+
//@ [chk_fail_yeet] run-crash
88
//
99
//@ [unchk_pass] compile-flags: -Zcontract-checks=no
1010
//@ [chk_pass] compile-flags: -Zcontract-checks=yes

tests/ui/contracts/internal_machinery/contract-ast-extensions-nest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
//@ [unchk_fail_post] run-pass
66
//@ [chk_pass] run-pass
77
//
8-
//@ [chk_fail_pre] run-fail
9-
//@ [chk_fail_post] run-fail
8+
//@ [chk_fail_pre] run-crash
9+
//@ [chk_fail_post] run-crash
1010
//
1111
//@ [unchk_pass] compile-flags: -Zcontract-checks=no
1212
//@ [unchk_fail_pre] compile-flags: -Zcontract-checks=no

tests/ui/contracts/internal_machinery/contract-ast-extensions-tail.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
//@ [unchk_fail_post] run-pass
66
//@ [chk_pass] run-pass
77
//
8-
//@ [chk_fail_pre] run-fail
9-
//@ [chk_fail_post] run-fail
8+
//@ [chk_fail_pre] run-crash
9+
//@ [chk_fail_post] run-crash
1010
//
1111
//@ [unchk_pass] compile-flags: -Zcontract-checks=no
1212
//@ [unchk_fail_pre] compile-flags: -Zcontract-checks=no

tests/ui/contracts/internal_machinery/contract-intrinsics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
//@ [default] run-pass
44
//@ [unchk_pass] run-pass
55
//@ [chk_pass] run-pass
6-
//@ [chk_fail_requires] run-fail
7-
//@ [chk_fail_ensures] run-fail
6+
//@ [chk_fail_requires] run-crash
7+
//@ [chk_fail_ensures] run-crash
88
//
99
//@ [unchk_pass] compile-flags: -Zcontract-checks=no
1010
//@ [chk_pass] compile-flags: -Zcontract-checks=yes

tests/ui/contracts/internal_machinery/contract-lang-items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//@ [unchk_fail_post] run-pass
55
//@ [chk_pass] run-pass
66
//
7-
//@ [chk_fail_post] run-fail
7+
//@ [chk_fail_post] run-crash
88
//
99
//@ [unchk_pass] compile-flags: -Zcontract-checks=no
1010
//@ [unchk_fail_post] compile-flags: -Zcontract-checks=no

tests/ui/extern/extern-types-field-offset.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ run-fail
1+
//@ run-crash
22
//@ check-run-results
33
//@ exec-env:RUST_BACKTRACE=0
44
//@ normalize-stderr: "(core/src/panicking\.rs):[0-9]+:[0-9]+" -> "$1:$$LINE:$$COL"

tests/ui/mir/alignment/borrow_misaligned_field_projection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ run-fail
1+
//@ run-crash
22
//@ ignore-i686-pc-windows-msvc: #112480
33
//@ compile-flags: -C debug-assertions
44
//@ error-pattern: misaligned pointer dereference: address must be a multiple of 0x4 but is

tests/ui/mir/alignment/misaligned_borrow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ run-fail
1+
//@ run-crash
22
//@ ignore-i686-pc-windows-msvc: #112480
33
//@ compile-flags: -C debug-assertions
44
//@ error-pattern: misaligned pointer dereference: address must be a multiple of 0x4 but is

tests/ui/mir/alignment/misaligned_lhs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ run-fail
1+
//@ run-crash
22
//@ ignore-i686-pc-windows-msvc: #112480
33
//@ compile-flags: -C debug-assertions
44
//@ error-pattern: misaligned pointer dereference: address must be a multiple of 0x4 but is

tests/ui/mir/alignment/misaligned_mut_borrow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ run-fail
1+
//@ run-crash
22
//@ ignore-i686-pc-windows-msvc: #112480
33
//@ compile-flags: -C debug-assertions
44
//@ error-pattern: misaligned pointer dereference: address must be a multiple of 0x4 but is

tests/ui/mir/alignment/misaligned_rhs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ run-fail
1+
//@ run-crash
22
//@ ignore-i686-pc-windows-msvc: #112480
33
//@ compile-flags: -C debug-assertions
44
//@ error-pattern: misaligned pointer dereference: address must be a multiple of 0x4 but is

tests/ui/mir/alignment/two_pointers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ run-fail
1+
//@ run-crash
22
//@ ignore-i686-pc-windows-msvc: #112480
33
//@ compile-flags: -C debug-assertions
44
//@ error-pattern: misaligned pointer dereference: address must be a multiple of 0x4 but is

tests/ui/mir/null/borrowed_mut_null.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ run-fail
1+
//@ run-crash
22
//@ compile-flags: -C debug-assertions
33
//@ error-pattern: null pointer dereference occurred
44

tests/ui/mir/null/borrowed_null.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ run-fail
1+
//@ run-crash
22
//@ compile-flags: -C debug-assertions
33
//@ error-pattern: null pointer dereference occurred
44

tests/ui/mir/null/borrowed_null_zst.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ run-fail
1+
//@ run-crash
22
//@ compile-flags: -C debug-assertions
33
//@ error-pattern: null pointer dereference occurred
44

tests/ui/mir/null/null_lhs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ run-fail
1+
//@ run-crash
22
//@ compile-flags: -C debug-assertions
33
//@ error-pattern: null pointer dereference occurred
44

tests/ui/mir/null/null_rhs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ run-fail
1+
//@ run-crash
22
//@ compile-flags: -C debug-assertions
33
//@ error-pattern: null pointer dereference occurred
44

tests/ui/mir/null/two_pointers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ run-fail
1+
//@ run-crash
22
//@ compile-flags: -C debug-assertions
33
//@ error-pattern: null pointer dereference occurred
44

tests/ui/panics/panic-in-cleanup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ run-fail
1+
//@ run-crash
22
//@ exec-env:RUST_BACKTRACE=0
33
//@ check-run-results
44
//@ error-pattern: panic in a destructor during cleanup

tests/ui/panics/panic-in-ffi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ run-fail
1+
//@ run-crash
22
//@ exec-env:RUST_BACKTRACE=0
33
//@ check-run-results
44
//@ error-pattern: panic in a function that cannot unwind

tests/ui/panics/panic-in-message-fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Checks what happens when formatting the panic message panics.
22

3-
//@ run-fail
3+
//@ run-crash
44
//@ exec-env:RUST_BACKTRACE=0
55
//@ check-run-results
66
//@ error-pattern: panicked while processing panic

tests/ui/precondition-checks/alignment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ run-fail
1+
//@ run-crash
22
//@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
33
//@ error-pattern: unsafe precondition(s) violated: Alignment::new_unchecked requires
44

tests/ui/precondition-checks/ascii-char-digit_unchecked.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ run-fail
1+
//@ run-crash
22
//@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
33
//@ error-pattern: unsafe precondition(s) violated: `ascii::Char::digit_unchecked` input cannot exceed 9
44

tests/ui/precondition-checks/assert_unchecked.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ run-fail
1+
//@ run-crash
22
//@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
33
//@ error-pattern: unsafe precondition(s) violated: hint::assert_unchecked must never be called when the condition is false
44

tests/ui/precondition-checks/char-from_u32_unchecked.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ run-fail
1+
//@ run-crash
22
//@ compile-flags: -Copt-level=3 -Cdebug-assertions=no -Zub-checks=yes
33
//@ error-pattern: unsafe precondition(s) violated: invalid value for `char`
44

0 commit comments

Comments
 (0)