rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.65k stars 12.75k forks source link

Accessing field .offset inside test crashes test harness if incorrect #108087

Open dns2utf8 opened 1 year ago

dns2utf8 commented 1 year ago

While writing this bug report I realised a bug in my code that I never wrote to the file. After I fixed that the tests summaries start to show up, but the details (stdout per failed test) are still missing.

Am I not allowed to call a symbol offset?

I tried this code:

pub struct ActiveFile {
    /// Clonable needed for metadata
    pub(crate) id: FileTag,
    /// The actual data buffer
    data: Vec<u8>,
    /// seekable
    offset: usize,
    /// Locked file
    real_file: File,
}

impl Drop for ActiveFile { ... }
impl Write for ActiveFile { ... }

#[cfg(test)]
mod tests {
    use super::*;
    use ring::aead::{BoundKey, UnboundKey};
    use std::path::PathBuf;

    #[test]
    fn simple_write() {
        let mut key = test_key();
        let mut a = ActiveFile::open_rwlocked(&path("simple_write.bin"), FileTag(1), &mut key)
            .expect("unable to open test file");

        a.write(b"abc").unwrap();
        println!("a.data: {:?}", a.data);
        assert_eq!(3, a.data.len());
    }

I expected to see this happen: explanation

Instead, this happened: The code compiles starts running and crashes without printing the test cases (passed or failed). The only way to get them to work is by removing assert_eq!(3, a.offset); from the test

(signal: 6, SIGABRT: process abort signal)

Meta

rustc --version --verbose, tried it with nightly too -> same result:

rustc 1.67.1 (d5a82bbd2 2023-02-07)
binary: rustc
commit-hash: d5a82bbd26e1ad8b7401f6a718a9c57c96905483
commit-date: 2023-02-07
host: x86_64-unknown-linux-gnu
release: 1.67.1
LLVM version: 15.0.6

There is no backtrace, just the short message

running 1 test
thread panicked while panicking. aborting.
error: test failed, to rerun pass `-p aead_vfs --lib`

Caused by:
  process didn't exit successfully: `$HOME/rust/encrypted_filesystem_storage/target/debug/deps/aead_vfs-dbf5b5fd9b41c8b0 secure_file` (signal: 6, SIGABRT: process abort signal)
workingjubilee commented 1 year ago

@dns2utf8 The code you linked and the code in your sample differs, could you doublecheck to make sure the report is correct and complete and edit it if not? Thanks! That will help when we follow up on this.