Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STATUS_HEAP_CORRUPTION crashes are hidden by the test harness #65692

Closed
glandium opened this issue Oct 22, 2019 · 1 comment · Fixed by rust-lang/cargo#7535
Closed

STATUS_HEAP_CORRUPTION crashes are hidden by the test harness #65692

glandium opened this issue Oct 22, 2019 · 1 comment · Fixed by rust-lang/cargo#7535
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@glandium
Copy link
Contributor

Consider the following code:

fn main() {
    use std::alloc::{alloc, dealloc, Layout};
    unsafe {
        let ptr = alloc(Layout::from_size_align(4096, 4096).unwrap());
        dealloc(ptr, Layout::from_size_align(4096, 1).unwrap());
    }
}

Yes, it breaks the invariants for dealloc, and yes, it crashes on Windows, with:

error: process didn't exit successfully: `target/debug/foo.exe` (exit code: 0xc0000374, STATUS_HEAP_CORRUPTION)

The problem is that when that happens in a test, the test just fails in a completely non-useful manner. (just switch to a lib crate, rename the function and add #[test]).

The test fails with:

running 1 test
error: test failed, to rerun pass '--lib'

And nothing else.
When the crate happens to have other tests, some other tests, but not all, will show test foo... ok, then the same error.

@jonas-schievink jonas-schievink added A-testsuite Area: The testsuite used to check the correctness of rustc C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Oct 22, 2019
@ehuss
Copy link
Contributor

ehuss commented Oct 23, 2019

I don't think this is something libtest can do anything about, since once the process has crashed, it is no longer running. I think this is a Cargo issue where it is not displaying the exit message properly.

I have opened rust-lang/cargo#7535 with a fix.

You still won't see which individual test caused the error, but presumably you can attach a debugger or something in this scenario (or whittle it down manually). There is experimental support in libtest to run each test in a separate process (for panic=abort tests), which could maybe be extended in the future to be something you could opt in to in order to narrow down which test failed.

bors added a commit to rust-lang/cargo that referenced this issue Oct 23, 2019
Show better error message for Windows abnormal termination.

This helps display better error messages when there is an abnormal termination on Windows.

If rustc crashes, there was a slight mistake in #6270, where the error code was actually negative, so the message was getting hidden behind the `--verbose` flag.  This changes it show that the abnormal error is always shown if rustc crashes in an unusual way.

This also changes `cargo test` to display a better message if the test crashes.  Previously:

```
running 1 test
error: test failed, to rerun pass '--bin crash'
```

New:

```
running 1 test
error: test failed, to rerun pass '--bin crash'

Caused by:
  process didn't exit successfully: `D:\Temp\crash\target\debug\deps\crash-b3c2389529da3d3e.exe` (exit code: 0xc0000374, STATUS_HEAP_CORRUPTION)
```

I didn't add any tests because testing on this on Windows seems a little precarious.  AFAIK, the exact error message depends on the processor (like x86 vs i686), and Windows version.  I was concerned about chasing down every little nuance, though I'm willing to try if it seems important.

Fixes rust-lang/rust#65692 (I think).
bors added a commit to rust-lang/cargo that referenced this issue Oct 24, 2019
Show better error message for Windows abnormal termination.

This helps display better error messages when there is an abnormal termination on Windows.

If rustc crashes, there was a slight mistake in #6270, where the error code was actually negative, so the message was getting hidden behind the `--verbose` flag.  This changes it show that the abnormal error is always shown if rustc crashes in an unusual way.

This also changes `cargo test` to display a better message if the test crashes.  Previously:

```
running 1 test
error: test failed, to rerun pass '--bin crash'
```

New:

```
running 1 test
error: test failed, to rerun pass '--bin crash'

Caused by:
  process didn't exit successfully: `D:\Temp\crash\target\debug\deps\crash-b3c2389529da3d3e.exe` (exit code: 0xc0000374, STATUS_HEAP_CORRUPTION)
```

I didn't add any tests because testing on this on Windows seems a little precarious.  AFAIK, the exact error message depends on the processor (like x86 vs i686), and Windows version.  I was concerned about chasing down every little nuance, though I'm willing to try if it seems important.

Fixes rust-lang/rust#65692 (I think).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants